Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Realloc- in Standard allocator

Tags:

c++

c++11

For the Standard allocator interface for use in, say, std::vector, is re-allocation supported? I have a rather specific use-case in which being able to realloc directly would be much more efficient than allocating, moving, and freeing.

Edit: Sorry- I have absolutely no intention of calling the actual realloc, I meant a function with those semantics. Effectively, I'm allocating off a stack in the background, and if I allocate more off the stack, then I can't free the memory underneath it, which is a total waste because there's no need to allocate again anyway as there's plenty of contiguous free space available. Thus, if I could be asked to reallocate in a single step, then I could avoid having to firstly, allocate some stuff and waste some memory, and secondly, move all the contents of the vector.

like image 213
Puppy Avatar asked Jun 17 '11 19:06

Puppy


1 Answers

We tried but failed:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1953.html

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2045.html

Edit: I know what you meant. ;-)

like image 100
Howard Hinnant Avatar answered Oct 09 '22 12:10

Howard Hinnant