开发者

Is there a difference between boost iostream mapped file and boost interprocess mapped file?

I want to create a mapped binary file into memory; however I am not sure how to create the file to be mapped into the system. I read the documentation several times开发者_运维知识库 and realize there are 2 mapped file implementations, one in iostream and the other in interprocess.

Do you guys have any idea on how to create a mapped file into shared memory? I am trying to allow a multi-threaded program to read an array of large double written in a binary file format. Also what is the difference between the mapped file in iostream and interprocess?


As far as I can tell, iostreams will place the mapped file in shared memory (this is what you want); however, interprocess however places the file in a another process's address space.

You should probably use iostreams unless you have multiple processes (not threads) that will be communicating with each other in some way.


The chief difference I see between the two is how they are used. In boost-interprocess, to use a memory mapped file, you create objects in that memory space using placement new, and those objects are automatically persistent in binary form in your file. Other processes can then map the same file and use those objects, or the program itself can use it as a persistent cache and reload them later. Memory mapped files in boost-iostreams act just like file streams, with the added benefits of being a boost::iostream, and would provide stream semantics to interprocess communication.

For a single process, there isn't much benefit to using boost::iostream memory mapped files. However, it can reduce the latency in working with the file as it will have already been loaded into memory. But, you only gain this benefit if you are constantly rewriting parts of the file. For a single read/write pass of the file, there may not be any speed up.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜