What is needed and what the allocator in C++?

After passing one course, trying to understand what are and why do they need these allocator in C++. Explain, please their practical purpose and what they should do.
July 8th 19 at 11:25
3 answers
July 8th 19 at 11:27
Solution
The allocator is able to allocate and free memory in the required amount in a certain way. std::allocator -- an example of implementation of allocator from the standard library, just using new and delete, which are usually called system calls malloc and free.

A more complex example -- pool allocator. Times system calls the road, why would they not save? Select from 1 Gigabyte memory (for example), and then the allocator will provide the memory in the pool and increase the pointer head (again, simplified). Real memory allocation only one system call is almost there, hurray, hurray, the program has accelerated.

Actually, for this and need the allocator to insert their own, cool, custom, memory allocation, at any place. Most of the standard containers adopt them.
Plus, you can correct the problem with the memory Defrag with frequent allocations and exemptions. - buford_Hand41 commented on July 8th 19 at 11:30
I should add that malloc is not a system call and a function from the standard library with its prototype described in the stdlib.h - Faustino.Schaef commented on July 8th 19 at 11:33
July 8th 19 at 11:29
On habré there are a number of elegant and understandable articles, such as this:

Alternative memory allocator
July 8th 19 at 11:31
Very briefly - for performance.
And in more detail, for example what are the requirements to samopisnye the allocator and what should he do? - buford_Hand41 commented on July 8th 19 at 11:34
: And why would mu e to open the documentation and read the requirements: en.cppreference.com/w/cpp/concept/Allocator - Faustino.Schaef commented on July 8th 19 at 11:37

Find more questions by tags Memory managementC++