boost::匿名段上的进程间内存分配器
我正在尝试使用类似 mmap 的段在 stl 容器上分配对象,为此我正在使用 boost::interprocess,它提供内存映射、分配器和匿名内存映射支持。
有点像这个
我的问题是 anonymous_shared_memory
函数 此处返回一些内容看起来一半是映射文件,一半是共享内存(使用 mmap :) 是有意义的),尽管两种样式都适用于 进程间分配器 这个看起来缺少一个segment_manager,执行实际的块分配。
因为它返回一个已在进程中映射的高级mapped_region
,但没有管理器,并且我无法看到挂钩segment_manager
。
I'm trying to use an mmap-like segment to allocate objects on stl containers, for that I'm using boost::interprocess which provides with memory mappings, allocators and anonymous memory mapping support.
A bit like this
My problem is that the anonymous_shared_memory
function here returns something that looks half mapped file and half shared memory(makes sense with mmap :) ) and although both styles work with interprocess allocators this one looks like its missing a segment_manager which does the actual chunk allocation.
As it returns a high-level mapped_region
already mapped in the process but with no manager and no way that I can see to hook in a segment_manager
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
mapped_region 是一个中低级对象,从字面上看只代表内存。 托管共享内存,但是
因此它是拥有
segment_manager
的托管内存。假设您想使用
anonymous_shared_memory
,首先您需要按照示例获取memory_region
,然后您将使用放置new
来放置segment_manager
位于 开头它。它的构造函数采用它正在构建的内存段的大小。我不知道这是否包括管理器的大小,尽管我怀疑它包括在内。A
mapped_region
is a low to mid-level object, and literally represents just the memory. Managed shared memory, howeverso it is the managed memory that possess the
segment_manager
.Given that you want to use
anonymous_shared_memory
, first you'd get thememory_region
as per the example, then you would use placementnew
to put asegment_manager
at the beginning of it. Its constructor takes the size of the memory segment that it is being constructed in. I do not know if this includes the size of the manager, although I suspect it is included.