简体   繁体   English

boost iostream映射文件和boost进程间映射文件之间有区别吗?

[英]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. 我多次阅读文档并意识到有2个映射文件实现,一个在iostream中,另一个在进程间。

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. 我试图允许多线程程序读取以二进制文件格式写入的大型double数组。 Also what is the difference between the mapped file in iostream and interprocess? iostream中的映射文件和进程间的区别是什么?

As far as I can tell, iostreams will place the mapped file in shared memory (this is what you want); 据我所知,iostreams会将映射文件放在共享内存中(这就是你想要的); 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. 您应该使用iostream,除非您有多个进程(而不是线程)以某种方式相互通信。

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. boost-interprocess中 ,要使用内存映射文件,可以使用placement new在该内存空间中创建对象,并且这些对象在文件中以二进制形式自动持久化。 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. boost-iostream中的内存映射文件就像文件流一样,具有成为boost::iostream的额外好处,并为进程间通信提供流语义。

For a single process, there isn't much benefit to using boost::iostream memory mapped files. 对于单个进程,使用boost::iostream内存映射文件没有太大好处。 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. 对于文件的单个读/写传递,可能没有任何加速。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM