idea regarding std::allocator<>

1,183 views
Skip to first unread message

Oliver S.

unread,
Mar 29, 2019, 12:16:48 PM3/29/19
to ISO C++ Standard - Discussion
The containers like std::vector<> that rely on std::allocator usually allocate a new block when growing the capacity of the container. That's o.k. in many cases because If we could do something like reaölloc() in C (we usually can*'t because the objects can't be bit-copied) the block usually would get a new address. But when the block allocated through std::allocator<> is large enough, it is usually not backed by the fragmented C-style heap but by the virtual-memory-allocation-functions of the operatin-system (f.e. mmap() or VirtualAlloc). In this cases growing an allocation through a kind of std::allocator<> could be often done in-place because there is space left at the end of the allocation because the allocation is done on page-boundaries. So the thing is simply, that we can't do somehting like realloc(). But my idea is here that the std::allocator<> could be extended in a way that the using container could ask the allocator what's the current allocation-size of a certain memory-block before reallocating if necessary. So the container could grow the capacity without reallocation in many cases.
What do you think about this idea?
Reply all
Reply to author
Forward
0 new messages