[interprocess] placement new allocator for vector

I'd like to have a user type that contains a vector and yet is still binary serializable, *AND* that can be used entirely inside or outside of shared memory. My idea is to give the vector a placement new allocator, it goes like this: class MyBinarySerialType { struct SomeItem { char first[10]; char second[10]; }; SomeItem m_Items[16]; //The placement new allocator points with an offset_ptr<SomeItem> //to the location &m_Items[0] boost::interprocess::vector<SomeItem, /*placement new allocator*/> m_vItems; public: MyBinarySerialType(const /*placement new allocator*/ &alloc); } I'd like to know if interprocess allocators can already do this for me (via template params, etc) or if I need to write my own allocator. If this is done correctly, I think it means I can "new" MyBinarySerialType from the regular heap and it will work entirely outside of shared memory. Likewise if I use segment.construct<MyBinarySerialType>()(...), then the whole thing should be created inside of shared memory. Either way, the vector will allocate strictly to a piece of memory inside the size of the class. Brent Arias

Brent Arias wrote:
I'd like to know if interprocess allocators can already do this for me (via template params, etc) or if I need to write my own allocator. If this is done correctly, I think it means I can "new" MyBinarySerialType from the regular heap and it will work entirely outside of shared memory. Likewise if I use segment.construct<MyBinarySerialType>()(...), then the whole thing should be created inside of shared memory. Either way, the vector will allocate strictly to a piece of memory inside the size of the class.
No, you need to write your own allocator. Interprocess vector is a standard conforming vector that supports non-raw pointers, nothing else.
Brent Arias
Best, Ion
participants (2)
-
Brent Arias
-
Ion Gaztañaga