Is it possible to use custom allocator for std::vector
internal allocations? If yes, how?
Custom allocator in std::vector
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.
could you give an example –
Mechanical
@Mechanical Click on the link, it has tons of examples. –
Bellbottoms
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. –
Gualterio
At least I updated the link. The new page is referenced, as cppreference is a wiki. But your point is taken. –
Bellbottoms
Here is a running example derived from the reference. –
Vanward
© 2022 - 2024 — McMap. All rights reserved.
vector
callsnew
/delete
internally when the size changes. Those (de)allocations were meant by the word 'internal'. – Grappavector
callsalloc.allocate()
andalloc.deallocate()
when the size changes. – Matti