"Darius.Moos AT esigma-systems DOT de" <pfffffrrrrt@gmx.de> wrote in message news:<2i84tiFjh1vvU1@uni-berlin.de>...[color=blue]
> On Thu, 03 Jun 2004 09:31:32 +0200, Dave Moore wrote:
>[color=green]
> > However you can do what you want using the STL containers std::vector or
> > std::deque, which will grow automatically as you add data to them. They
> > also have functions to ensure you have enough space to hold a minimum
> > number of elements. However, one caveat is that each time they grow,
> > any pointers (or other iterators) into the container become invalid.[/color]
>
> Would you elaborate on this a little bit. Does "... become invalid" mean
> that the order and offset of the specific elements in the vector could
> change and therefor the pointers/iterators become invalid or does it mean
> that the order and offset of the vector-elements keep the same when adding
> (push_back()) to a vector and just the references become invalid due to
> some vector-internal management ?
>
> Thanks in advance for your answer.
>[/color]
Well, the terse answer is that they become invalid because the
Standard says so ... I guess the correct way to interpret this is that
the Standard places no restrictions on compiler developers to make
sure that they remain valid, as it does with (for example) std::list.
What that means in the end is that, it doesn't really matter *how*
they become invalid, but rather that you can no longer rely on them to
behave in the correct way.
Sorry if this is a somewhat unsatisfying answer, but I don't really
know the guts of the STL containers, only (some of) what is in the
Standard, which is all that is required for users. There are good
books and websites to help you learn more about implementation details
if you are interested ... try
www.accu.org for more info.
As far as your examples are concerned, I think that either of your
suggestions above might be a (partial) answer for a particular
implementation. Note however that if you start relying on a
particular behavior for something that is specified as undefined (or
even implementation-defined), then somewhere down the line your code
is probably going to break.
HTH, Dave Moore