Reputation: 30645
I'm using Boost Interprocess to map a vector in shared memory.
This is the code I have from Boost tutorials:
using namespace boost::interprocess;
using ShmemAllocator = allocator<int, managed_shared_memory::segment_manager>;
using MyVector = boost::interprocess::vector<int, ShmemAllocator> MyVector;
// question refers to this size
// V
managed_shared_memory segment(open_or_create, "MySharedMemory", 65536);
const ShmemAllocator alloc_inst (segment.get_segment_manager());
MyVector *myvector = segment.construct<MyVector>("MyVector")(alloc_inst);
myvector->resize(SIZE);
I resize my vector after creating the managed_shared_memory
.
However, what happens if the managed_shared_memory
size argument is smaller than the vector memory allocation?
Rewording the question: how do I choose a size for the managed_shared_memory
?
Upvotes: 1
Views: 945
Reputation: 393769
However, what happens if the managed_shared_memory size argument is smaller than the vector memory allocation?
Have you tried? Live Demo:
terminate called after throwing an instance of 'boost::container::length_error'
what(): get_next_capacity, allocator's max size reached
Rewording the question: how do I choose a size for the managed_shared_memory?
Carefully. Seriously, see e.g.:
Also, segments can be resized/grown, and I have multiple answers on that ranging from simple to advanced: https://stackoverflow.com/search?tab=newest&q=user%3a85371%20interprocess%20grow
Upvotes: 1