Is it possible to use custom allocator for std::vector internal allocations? If yes, how?
1 Answer
You basically have to implement your allocator type to conform to the Allocator concept.
The linked page lists all requirements of that type, but the core functionality is implemented in the allocate member function.
5 Comments
serup
could you give an example
bitmask
@serup Click on the link, it has tons of examples.
dtell
This is exactly the reason why link only answers are bad! The page doesn't exist anymore. Pointing towards examples in the broken link is even worse.
bitmask
At least I updated the link. The new page is referenced, as cppreference is a wiki. But your point is taken.
schoetbi
Here is a running example derived from the reference.
vectorcallsalloc.allocate()andalloc.deallocate()when the size changes.