"Victor Bazarov" <v.Abazarov@comAcast.net> wrote in message
news:O0usb.181597$Tr4.505377@attbi_s03...
"Noo" <arGG@HHsys.uea.ac.uk> wrote...
Hi. I've got some code that uses vectors fairly extensively and it needs
to
be efficient. Therefore I'm using reserve() quite a bit. However what
other
functions (are supposed to) change the capacity?
All that may lead to 'insert', if such change is necessary.
I know that adding extra elements (e.g. by using push_back()) may do
this,
if extra capacity is needed.
Why do you think you actually need the capacity? The whole idea
of 'reserving' some space is to [try to] avoid reallocations if
'push_back' is used.
Understood. The problem I was having was that, after reserving space in the
vector, some other call was reducing the capacity. I only noticed when the
profiler showed me how much time was being taken by push_back() calls
On the C++ implementation I'm using:
clear() seems to reset the capacity to zero.
Even if it seems to, it doesn't necessarily do so.
Well, 'v.clear()' followed by 'cout << v.capacity()' gave the answer 0,
though whether it would always do that...
resize() leaves the capacity as is.
Depends on whether you resize it beyond current capacity or not.
Sorry. Meant to write resize(0).
And, perhaps, getting and reading a good book on Standard Library
would help. I recommend the one by Nicolai Josuttis.
Indeed, it's a great book! I'd be posting here more often without it!
Thanks for the help,
Alan
.