In short, my question is: if you have a class, MyClass<T>how can you change the class definition to support when you have it MyClass<T, Alloc>, similar to how, for example, the STL vector is provided.
I need this functionality to support a shared memory allocator. In particular, I am trying to implement a ring buffer in shared memory. He currently has the following ctor:
template<typename ItemType>
SharedMemoryBuffer<ItemType>::SharedMemoryBuffer( unsigned long capacity, std::string name )
where ItemTypeis the type of data that should be placed in each slot in the buffer.
Now it works great when I create a buffer from the main program, this way
SharedMemoryBuffer<int>* sb;
sb = new SharedMemoryBuffer<int>(BUFFER_CAPACITY + 1, sharedMemoryName);
However, in this case, the buffer itself is not created in the shared memory and therefore is not available for other processes. I want to do something like
typedef allocator<int, managed_shared_memory::segment_manager> ShmemAllocator;
typedef SharedMemoryBuffer<int, ShmemAllocator> MyBuffer;
managed_shared_memory segment(create_only, "MySharedMemory", 65536);
const ShmemAllocator alloc_inst (segment.get_segment_manager());
MyBuffer *mybuf = segment.construct<MyBuffer>("MyBuffer")(alloc_inst);
, .