About std::vector::resize().
Carlo Wood
carlo@alinoe.com
Thu May 27 16:19:00 GMT 2004
On Thu, May 27, 2004 at 07:45:11AM +0530, Dhruv Matani wrote:
> This is not the full version, because your patch will have to be
> patched, and the functions will have to be specialized for vector<T>,
> list<T>, map<T>, etc... where we may assume that.
Ah, you want to specialize it. But why not do this very every vector?
If you have say, std::vector<Foo>, then that would result in the need
to std::swap(foo1, foo2). How is swap implemented for arbitrary objects?
By calling a copy constructor, an assignment operator and a destructor
I assume. Ok, so that would be _slower_ than the current implementation.
But it would also allow to make it faster. Consider you have this:
class Foo {
std::vector<double> M_v;
// ...
};
Then you could speed up growing the capacity of std::vector<Foo>
considerably by overloading std::swap(Foo, Foo) :).
On the other hand - when we'd demand such 'tricks' from users
to get the speed or else they'll a slower result even - then
they might as well specialize std::uninitialized_copy for their
type themselfs to begin with.
If you go for specializing __uninitialized_copy_swap for only our
own vector, then note that there is no need to call a constructor
at all (or swap). You can just move the three members of the
vector over and dealloc the old space, in fact - the fastest
would be to just memcpy the old vector to its new allocation.
No need for default constructors and swap members :/
--
Carlo Wood <carlo@alinoe.com>
More information about the Libstdc++
mailing list