开发者

Does boost support circular files?

I need to use a circular file to keep a large amount of dynamic data (write-once, probably never read) on disk.

To be 开发者_如何学Pythonmore clear, I want to treat a file as a circular buffer - i.e. writes to the buffer will go to the file, and reads will be file reads. Specifically I'm doing logs.

I was wondering if boost has any functionality that I can use (ideally a circular file).

I saw there is a circular buffer in boost, but I can't use it with a file as some sort of back-end. I have even thought about mmap()-ing the file into memory (which will not be a good solution if I use logs with more than 4GBs in size), and returning the mapped chunk back from the Allocator that I will pass to the buffer.

This seems to be a bad approach since the circular buffer documentation says that Allocator will be used for any memory allocation (and not just the buffer allocation).

Is there any other functionality for circular files, or some other way to do this?

Well, I actually meant logging in the sense of file-system logs (that is logging writes). I have a disk that I want to log (the writes to it) so that I can do CDP. I need to keep a log of all the writes, and of the marks so that I can roll the disk back to a position it was at earlier.

The logs may have a lot of space (over 10GB easily), so I don't know if the mmap solution would work.


How about using Boost's Circular Buffer + Boost IPC's memory mapped file? The IPC documentation says its possible: http://www.boost.org/doc/libs/1_46_0/doc/html/interprocess/allocators_containers.html (see the last line).


Is RRDtool acceptable? It's in C, rather than C++, but hopefully building an object-oriented shim around the API wouldn't be too awful.


You tagged your question as Linux, and you are writing log files, so configure logrotate for your application. It is more than flexible enough to do what you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜