Boost logo

Boost Users :

Subject: Re: [Boost-users] [Interprocess] Using existing containers after grow()
From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2015-03-10 18:09:03

El 04/03/2015 a las 14:36, Malko escribió:
> Hi,
> I am having some difficulties understanding the relationship between
> allocators for containers and grow().
> Let's say I create a vector (whatever type) in shmem, then I unmap
> everything and proceed to grow the shmem from 1MB to 2MB and remap.
> I can now access my old vector and start adding new entries.
> What I am unsure about is: would this vector be able to create new entries
> until the whole 2MB are allocated, or would it stop at 1?

Yes, it should be able to grow until 2MB (or something near it,
depending on the memory allocator overhead, fragmentation, etc.

> I have not seen anywhere in the docs any warning about the need to
> construct new containers after a grow, so I assume my vector can grow up
> to to 2MB now. Then my question is: how does it know that now it can grow
> up to 2MB if the allocator I passed on construction was instantiated from
> a segment_manager that knew about a shmem of size 1MB? Is there somewhere
> in shared memory a segment_manager-like object that stores info about the
> shmem itself (and can I access it in my code)?

The allocator stores a pointer to the segment manager, which is
constructed at the beginning of the shared memory segment. When the
shared memory object is extended, the information stored at the
beginning of the segment is updated and all containers holding a shared
memory allocator automatically can access the newly extended memory.



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