Re: Pointer To A Vector Elements While Still Adding
From: Donovan Rebbechi (abuse_at_aol.com)
Date: 03/27/05
- Next message: Ioannis Vranos: "Re: Pointer To A Vector Elements While Still Adding"
- Previous message: marbac: "Re: [OT]Re: ctor, operator ="
- In reply to: Adam Hartshorne: "Re: Pointer To A Vector Elements While Still Adding"
- Next in thread: Howard Hinnant: "Re: Pointer To A Vector Elements While Still Adding"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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/
- Next message: Ioannis Vranos: "Re: Pointer To A Vector Elements While Still Adding"
- Previous message: marbac: "Re: [OT]Re: ctor, operator ="
- In reply to: Adam Hartshorne: "Re: Pointer To A Vector Elements While Still Adding"
- Next in thread: Howard Hinnant: "Re: Pointer To A Vector Elements While Still Adding"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|