This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
[Off topic] Re: C++ arrays vs vectors
- To: egcs at cygnus dot com (egcs at cygnus dot com)
- Subject: [Off topic] Re: C++ arrays vs vectors
- From: Carlo Wood <carlo at runaway dot xs4all dot nl>
- Date: Thu, 27 Aug 1998 19:13:02 +0200 (CEST)
| 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.