10 ms·
The (new in c++17) polymorphic allocators allow this, as you can instantiate a monotonic_memory_resource, and use it to construct all the regular C++ containers
by frutiger 10y ago
The (new in c++17) polymorphic allocators allow this, as you can instantiate a monotonic_memory_resource, and use it to construct all the regular C++ containers with it for the duration of the remaining scope - this works just fine as long as no memory is needed outside of that scope.
- galacticpony 10y ago...so preoccupied with whether or not they could, they didn’t stop to think if they should.
- blt 10y agoThat's cool. Do the C++ containers now contain a pointer to the monotonic_memory_resource, or is there some magic that lets the local calls to push_back, etc., know about the allocator in that local scope? When I needed many arena-backed vectors, I wrote an ArenaVec with an API that takes a pointer to the arena in all methods that can allocate, keeping the memory size down.
- frutiger 9y agoYes they do, but since c++11, allocators were not required to be stateless. As a result, containers (or any allocator-aware objects) have needed to hold an instance of the allocator.