Overview of the C++ allocation operators
In C++, there are many (infinitely many!) flavors of memory allocation operators, but there are rules to follow when writing your own. The current chapter is mostly about those rules; the chapters that follow will explore ways to benefit from this freedom C++ gives us:
- C++ lets us overload the global versions of the memory allocation operators. If we do so, then even things such as
new intwill use our homemade versions. One has to be careful here since small mistakes can have a significant impact on code execution: if your implementation ofoperator new()is slow, you will slow down most memory allocations in your program! We will use this approach when writing a simple-yet-working leak detector in Chapter 8. - C++ lets us overload member function versions of the memory allocation operators. If we do, then the global versions (overloaded or not) apply in general, but the member function versions apply for specific types. This can...