-
Book Overview & Buying
-
Table Of Contents
C++ Memory Management
By :
As mentioned already, allocators have been a mainstay of C++ for decades now, but they have existed in a few different guises and shapes. In this chapter, we will adopt a sort of chronological approach, starting from the earlier (and more complicated) allocator types and progressing toward the simpler (and more versatile) ones.
To understand this chapter, one key idea to keep in mind is that a container type such as std::vector<T> does not really exist. What does exist is the std::vector<T,A> type where, by default, A is std::allocator<T>, which allocates through ::operator new() and deallocates through ::operator delete(). By traditional allocator, we mean an allocator type that is part of the type of a container (this is not the only possible approach to writing allocators today, as we will see when we discuss PMR allocators later in this chapter).
We will first examine what was required to write an allocator before C++11,...