Boost logo

Boost Users :

Subject: [Boost-users] [interprocess] placement new allocator for vector
From: Brent Arias (Brent.Arias_at_[hidden])
Date: 2009-04-08 18:13:05

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;

  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

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at