boost::interprocess memory allocator on anonymous segment
Asked Answered
W

1

7

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.

Wye answered 16/8, 2011 at 15:26 Comment(1)
If anonymous_shared_memory does not conform to the protocol interprocess allocators expect, it sounds like a bug. I recommend you to try reporting it.Unitary
H
3

A mapped_region is a low to mid-level object, and literally represents just the memory. Managed shared memory, however

is an advanced class that combines a shared memory object and a mapped region that covers all the shared memory object,

so it is the managed memory that possess the segment_manager.

Given that you want to use anonymous_shared_memory, first you'd get the memory_region as per the example, then you would use placement new to put a segment_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.

Hawkie answered 22/8, 2011 at 2:56 Comment(5)
@Arkaitz, have you tried this? Would you like me to put together some code for it?Hawkie
please do; it would be helpful!Supertanker
@EiyrioüvonKauyf it has been a very long time since I looked at this, so if I don't post code this weekend for it, poke me again.Hawkie
@EiyrioüvonKauyf I thought I recognized the unpronounceable name ... :)Hawkie
@EiyrioüvonKauyf not entirely sure what you are asking for.Hawkie

© 2022 - 2024 — McMap. All rights reserved.