Let's say I typedef a vector to be used in boost shared memory. When creating it, I have to give an allocator from a managed_shared_memory, which makes sense.
If I want to use this same vector type but to allocate it not in shared memory but instead allocating it on the standard process memory space.
Is it possible by giving a different allocator to the object ?
Do I have to change the definition of my vector to be able to accept both implementations ?
Is it impossible to do and therefore I should use a different kind of vector instead ?
Sample code I am trying to fix :
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/containers/vector.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
using namespace boost::interprocess;
typedef managed_shared_memory::segment_manager SegmentMgr;
typedef allocator<int, SegmentMgr> IntAlloc;
typedef vector<int, IntAlloc> IntVector;
int main()
{
shared_memory_object::remove("Boost");
managed_shared_memory managed_shm{ open_or_create, "Boost", 1024 };
IntAlloc intAlloc = managed_shm.get_segment_manager();
IntVector vectorInSharedMemory({}, intAlloc); // <--- this allocates in shared memory
IntVector vectorInMyOwnPrivateMemorySpace({}, /* ? */); // <--- is there a trick here ?
return 0;
}