Re: allocating stl containers in memory buffer
From: Victor Bazarov (v.Abazarov_at_comAcast.net)
Date: 01/01/05
- Next message: Rolf Magnus: "Re: Happy New Year!"
- Previous message: Mike Wahler: "Re: Happy New Year!"
- In reply to: Tomasz Grobelny: "allocating stl containers in memory buffer"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 1 Jan 2005 16:30:08 -0500
"Tomasz Grobelny" <grotk@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
- Next message: Rolf Magnus: "Re: Happy New Year!"
- Previous message: Mike Wahler: "Re: Happy New Year!"
- In reply to: Tomasz Grobelny: "allocating stl containers in memory buffer"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|