Recently, I became interested in tracking memory allocation and deallocation. When overloading the new and delete operators, I found that the C++ standard library sometimes calls the overloaded operators and sometimes allocates memory using other methods. (Probably std::allocator
.) For instance, std::string
seems not to use new
. Although, std::vector
seems to call new
when push_back
is called. This is surprising since I would think the standard library would have a uniform policy to manage memory allocation.
When does the standard library choose to new
vs std::allocator
? Why?