473,398 Members | 2,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Custom placement for vector

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.

May 21 '06 #1
4 2625
sr*********@gmail.com wrote:
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
May 21 '06 #2
In article <11**********************@j33g2000cwa.googlegroups .com>,
sr*********@gmail.com wrote:
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".
May 21 '06 #3

Mark P wrote:
sr*********@gmail.com wrote:
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


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?

May 21 '06 #4
* sr*********@gmail.com:
Mark P wrote:
sr*********@gmail.com wrote:
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


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.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
May 21 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Peter Olcott | last post by:
I have just built a class that provides the most useful subset of std::vector functionality for use by compilers that lack template capability. http://home.att.net/~olcott/std_vect.html ...
15
by: Alex Vinokur | last post by:
I am looking for any custom allocator sample code for std::vector. Thanks. -- Alex Vinokur http://mathforum.org/library/view/10978.html http://sourceforge.net/users/alexvn
8
by: elviin | last post by:
Hello. I tried a sample programm using placement new. I am not sure if i understand this technique correctly. I do not mean usage but a real world application. Could anyone to describe some...
15
by: natespamacct | last post by:
Hi All, I'm not sure if I'm dealing with a C++ question or a compiler question, so please forgive me if I'm asking in the wrong spot. If so, maybe someone can direct me to more appropriate spot....
15
by: mangesh | last post by:
This code is from c++ faq in section 11 : void someCode() { char memory; void* p = memory; Fred* f = new(p) Fred(); f->~Fred(); // Explicitly call the destructor for the placed object }
1
by: SarahT | last post by:
Hi folks, I am doing something Very Bad and Wrong (which I'll spare you the details of) that requires overloading new for some specific classes. So, for example: class MyWeirdThingy {...
4
by: Anu | last post by:
Hi, We have a class that has its own overloaded operator new and whose prototype seems to correspond to the standard placement new :- class AppClass { public: operator new (size_t size,...
9
by: karthikbalaguru | last post by:
Hi, I find that articles stating that 'placement new' constructs an object on a pre-allocated buffer and so takes less time. Actually, we have to consider the allocation of the buffer and then...
11
by: letz | last post by:
Hi, We have a class whose objects are to be allocated in shared memory. To do that a ShmManager base class is defined so that operator new and delete are redefined to allocate segments in shared...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.