Custom placement for vector

S

sreedhar.cs

Hi all,
In my application,I want to place a vector in a specific
location in shared memory.(a user supplied pointer).
I understand that the STL allocator mechanism places the data objects
within the STL vector in a user specified location in memory.Still the
STL container (vector) resides only within the process address space.
But I would want my STL container class(the vector skeleton as such)
as well as the data objects to be placed in shared memory. (in the same
or different segments ).
Plz tell me how to go about in this.

Thanks in Advance.
 
M

Mark P

Hi all,
In my application,I want to place a vector in a specific
location in shared memory.(a user supplied pointer).
I understand that the STL allocator mechanism places the data objects
within the STL vector in a user specified location in memory.Still the
STL container (vector) resides only within the process address space.
But I would want my STL container class(the vector skeleton as such)
as well as the data objects to be placed in shared memory. (in the same
or different segments ).
Plz tell me how to go about in this.

Thanks in Advance.

The allocator lets you control the location of the vector's dynamic
allocation. You can use placement new to control the location of the
vector proper.

Mark
 
D

Daniel T.

Hi all,
In my application,I want to place a vector in a specific
location in shared memory.(a user supplied pointer).
I understand that the STL allocator mechanism places the data objects
within the STL vector in a user specified location in memory.Still the
STL container (vector) resides only within the process address space.
But I would want my STL container class(the vector skeleton as such)
as well as the data objects to be placed in shared memory. (in the same
or different segments ).
Plz tell me how to go about in this.

I would say don't do it. Instead use a c_array like class, for example
the one in "The C++ Programming Language".
 
S

sreedhar.cs

Mark said:
The allocator lets you control the location of the vector's dynamic
allocation. You can use placement new to control the location of the
vector proper.

Mark

Mark,
Plz tell me how to use placement new for a vector .
The implementation of a vector might use placement new by
itself.
How can I override the existing placement new for a vector?
 
A

Alf P. Steinbach

* (e-mail address removed):
Mark,
Plz tell me how to use placement new for a vector .
The implementation of a vector might use placement new by
itself.
How can I override the existing placement new for a vector?

A std::vector object contains at least one pointer to an internal buffer.

To make the vector work in shared memory you'd have to (1) make sure
that the vector's internal buffer is allocated from some shared memory
region A, and (2) make sure that region A has the same logical start
address in all processes accessing the vector.

Since it's highly unlikely that you'll be able to do that, and since you
have no guarantee that there aren't any other pointers, you're almost
guaranteed to fail in this approach.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top