This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: About std::vector::resize().


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]