This is the mail archive of the
mailing list for the libstdc++ project.
Re: Amortized Analysis
Kevin Atkinson wrote:
> Personally I think all STL containers should have a shrink method so that
> the container can shrink to the exact size needed once you are done adding
> to it. I know you can always create a new container and make a copy but
> this has the potential to be not as efficient as just freeing the unused
> memory. Because in some cases this memory can be freed without any
> copying or reallocation being done. For example in the case of very large
> strings which are allocated with mmap.
reserve() can be used to release unused space, although it's
an implementation detail whether reserve() actually releases
any memory or not.