"Tomasz Grobelny" <gr***@poczta.onet.pl> wrote...
Is it possible to create for example stl queue in previously allocated
memory buffer (memory shared between two processes)? I thought of sth like
that:
queue<int>* q=new(buffer) queue<int>;
but won't integer variables (and possible others needed by queue object)
be
allocated using default allocator outside the buffer? How to force
allocation in specified buffer? Access to shared memory is protected by
semaphores so the should be no problem with amount of requested memory.
And
how do I force the second program to view the buffer as queue<int>? Is
casting enough?
With standard containers there are two allocations you need to concern
yourself with. One is the object of the type 'queue<int>' and the other
is for every contained 'int'. First one you definitely can allocate in
whatever buffer by using the method you showed (placement new). To use
any special memory for the other allocation, you need to supply your
[custom] allocator to your queue object.
Implementing custom allocators is a subject for a chapter in a book, so do
look it up in your favourite C++ book that deals with standard containers.
Good luck!
V