[Off topic] Re: C++ arrays vs vectors
Carlo Wood
carlo@runaway.xs4all.nl
Thu Aug 27 13:38:00 GMT 1998
| Several people, including Dr Stroustrup, recommended assuming contiguous
| vectors anyway, and avoiding any hypothetical weird STL implementation
| that does it differently (nobody knew of any in the real world).
A vector<> implementation that is not contiguous could have the advantage
that when the vector needs to be enlarged, and a realloc() would cause a
need for moving the data, then instead one doesn't need to move the
existing data.
Likewise, I already implemented my own streambuf class which never moves
data. It speeds things up considerably when you deal with sudden, large,
dynamic expansions.
--
Carlo Wood <carlo@runaway.xs4all.nl>
PS I wish the malloc() interface was extended with a
second `realloc()' that decreased the size of the
allocated block by leaving the data at the end at
the same point:
before: [xxxxxxxxxxxxxxxxxxxxxxx]
after: [xxxxxxxxxxxxxxxx]
^
|__ returned ptr
And a third `realloc()' that fails
when the data needs to be moved.
More information about the Gcc
mailing list