39

Is it possible to use custom allocator for std::vector internal allocations? If yes, how?

7

1 Answer 1

18

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.

Sign up to request clarification or add additional context in comments.

5 Comments

could you give an example
@serup Click on the link, it has tons of examples.
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.
At least I updated the link. The new page is referenced, as cppreference is a wiki. But your point is taken.
Here is a running example derived from the reference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.