473,414 Members | 1,781 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,414 software developers and data experts.

How to keep element address in container

Hello,

It turns out that STL vector does not assure the constness of its stored
element address (memory location),
i guess by the time it dynamicly allocates new memory as new element get
pushed in, it might copy stored elements
to new locations.

Is there any container implementation attempted doing so or how to instruct
STL to keep the address of those stored elements ?
array might do, but it lacks some flexibility ... it helps a lot if clint
code could reference the elements in the container
by each individual address.

Regards

Jul 23 '05 #1
3 1553
Kai Wu wrote:
Hello,

It turns out that STL vector does not assure the constness of its
stored element address (memory location),
i guess by the time it dynamicly allocates new memory as new element
get pushed in, it might copy stored elements
to new locations.

Is there any container implementation attempted doing so or how to
instruct STL to keep the address of those stored elements ?
array might do, but it lacks some flexibility ... it helps a lot if
clint code could reference the elements in the container
by each individual address.


It's not clear what you mean by assuring the constness of the stored element
address.

Jonathan
Jul 23 '05 #2

Kai Wu wrote:
Hello,

It turns out that STL vector does not assure the constness of its stored element address (memory location),
i guess by the time it dynamicly allocates new memory as new element get pushed in, it might copy stored elements
to new locations.

Is there any container implementation attempted doing so or how to instruct STL to keep the address of those stored elements ?
array might do, but it lacks some flexibility ... it helps a lot if clint code could reference the elements in the container
by each individual address.

Regards


If you have a vector of pointers the address wont change

If you have a vector of objects then the address of objects will change
anytime the vector grows. You can reserve the size of vector before
adding any elements and this wont happen but I would recommend making a
vector of smart_ptrs instead

Raj

Jul 23 '05 #3
"Kai Wu" <ka******@nokia.com> writes:

[snip]
Is there any container implementation attempted doing so or how to instruct
STL to keep the address of those stored elements ?

[snip]

Here is a list of stadnard containers which do not invalidate
references to or addresses of elements:

list, map, set, multiset, multimap .

In addition to these there is deque, which does not invalidate
addresses or references when inserts to either end are performed,
but does invalidate references and addresses when inserts to the
middle are performed.

None of these containers is quite like vector, but one of them is
likely to fit your needs. Read about each of them and decide.

Jul 23 '05 #4

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

Similar topics

1
by: Wolfgang Lipp | last post by:
my question is: do we need container elements for repeating elements in data-centric xml documents? or is it for some reason very advisable to introduce containers in xml documents even where not...
0
by: Wolfgang Lipp | last post by:
From: Lipp, Wolfgang Sent: Tuesday, 27?January?2004 13:26 <annotation> the first eleven contributions in this thread started as an off-list email discussion; i have posted them here with...
8
by: Stan Brown | last post by:
http://oakroadsystems.com/nonce/zonk.htm (12 lines) >...
3
by: Markus Ernst | last post by:
Hello Reading the follwing document: http://www.w3.org/TR/WD-positioning-970131#In-flow it seems very clear that position:relative should be relative to the parent element. So in the following...
37
by: spam.noam | last post by:
Hello, Guido has decided, in python-dev, that in Py3K the id-based order comparisons will be dropped. This means that, for example, "{} < " will raise a TypeError instead of the current...
6
by: Jakob Bieling | last post by:
Hi, I want to move an element from a std::list to the end of the same list. To get this done, I thought I'd just do something like: std::list <intlst; lst.push_back (0); lst.push_back (1);...
16
by: Juha Nieminen | last post by:
I'm actually not sure about this one: Does the standard guarantee that if there's at least one element in the data container, then "--container.end()" will work and give an iterator to the last...
10
by: Chris Forone | last post by:
Hello Group, there is some memberfunc for std::valarray to return a pointer to the first element in the array. How do i use this? Thanx a lot. HAND Chris
5
by: montybytes | last post by:
Hi there, Although, I have already placed this question in the HTML/CSS section, perhaps it might be worthwhile asking the question here as well. I have a JavaScript function which retrieves...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.