Re: Pointer To A Vector Elements While Still Adding

From: Donovan Rebbechi (abuse_at_aol.com)
Date: 03/27/05


Date: Sun, 27 Mar 2005 01:05:03 +0000 (UTC)

On 2005-03-26, Adam Hartshorne <oracle3001@yahoo.com> wrote:
> While I am running this process, I have no idea what the final size of
> Vector V will be, as it dependent on a set of runtime input data.

So vector is inappropriate.

> I suppose I could use a list, but I would suggest I would have the same
> problem, that I require pointers to elements in the vector/list, and I

No. list iterators (and you really should be using iterators, not pointers,
as placeholders!) are not invalidated by insertion.

> am under the impression that when I add another element during the next
> iteration, the first pointer to Vector V that was set become invalid.

Well that's a problem for vectors, but not for lists. You need to rearrange
elements in a vector to reallocate or insert because of the fact that vectors
occupy contiguous memory. lists do not (each node stores the address of the
next node), so adding new elements (even inserting into the middle) does not
require copying/moving any of the old elements.

Cheers,

-- 
Donovan Rebbechi
http://pegasus.rutgers.edu/~elflord/


Relevant Pages

  • abstract containers: does such a thing exist, conceptually?
    ... code implementing that pattern? ... behaviour by the additional pointers. ... trigger adding- or removing-operations of other iterators... ... 2)graph = list of lists: The same as above but with its own allocator ...
    (comp.object)
  • Re: very strange pthread problem
    ... The worker threads need access to a class member function or two. ... STL vector so each index into the vector points to the list of pointers ... it's just storing the pointers to the STL lists and the vector ... Then I moved the whole thing to a single cpu Linux ...
    (comp.programming.threads)
  • Re: Implementing Lisp in C?
    ... What I did was to pack the pointers ... it meant bigger header blocks on boxed objects, ... Whenever the "to-visit" list becomes empty, ... both the garbage and to-visit lists are empty, ...
    (comp.lang.lisp)
  • Re: question about True values
    ... Not all empty objects have zero length, or even a length at all. ... example, iterators. ... lists, but the "if a:" doesn't work for them, so it's moot. ...
    (comp.lang.python)
  • Re: std::vector : begin, end and insert - Using Objects instead of ints
    ... vector< CPoint> vec; ... lists, which only have iterators. ... "overloaded pointers", and it is better to say that iterators are "an ... iterator approach to a loop. ...
    (microsoft.public.vc.mfc)

Loading