About std::vector::resize().
Paolo Carlini
pcarlini@suse.de
Thu Jun 24 17:47:00 GMT 2004
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.
More information about the Libstdc++
mailing list