This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: About std::vector::resize().
- From: Paolo Carlini <pcarlini at suse dot de>
- To: Dhruv Matani <dhruvbird at gmx dot net>
- Cc: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Thu, 24 Jun 2004 19:18:21 +0200
- Subject: Re: About std::vector::resize().
- References: <200405251846.i4PIkBZP032335@mururoa.inria.fr> <40B398E0.8060903@roguewave.com> <16563.46765.978155.407649@localhost.localdomain> <40B47702.3010707@suse.de> <20040526140755.GA11472@alinoe.com> <1085583428.1286.4.camel@localhost.localdomain> <20040527003349.GA29903@alinoe.com> <1085624111.1271.4.camel@localhost.localdomain> <20040527025700.GA6365@alinoe.com> <1085762128.1463.15.camel@localhost.localdomain> <1085771564.1463.21.camel@localhost.localdomain> <40B795C6.9090508@suse.de> <1085802150.1174.18.camel@localhost.localdomain> <40B84379.6050201@suse.de> <1085852904.14086.5.camel@localhost.localdomain> <40B9A6A5.7010502@suse.de> <1086790042.3800.95.camel@localhost.localdomain> <40D6E5BF.4090203@suse.de> <1088093645.1362.6.camel@localhost.localdomain>
Dhruv Matani wrote:
There is no parch for built-in types. The optimization is applicable
only for those types that are:
1. Heavy (copy construction/assignment is expensive)
2. swap is NOT implemented in terms of assignment.
If use with types other than these, then the vector will become slower.
Hummm....
Isn't the algorithm sketched by Carlo potentially useful also for builtin
types
One could implement a resize from size m to size n (n > m) as:
- Create new vector with size n, using the default constructor
for all elements.
- Swap the first m elements.
- Destroy the old vector.
You still avoid copying the first m elements...
Paolo.