Why would one overload allocation functions?
Before we start discussing how to overload memory allocation mechanisms, let’s take a step back and examine why one would want to do this. Indeed, most programmers (even experienced ones) never end up doing anything of the sort, and we could wager that a majority of programmers never thought they had a reason to do so. Yet, we will allocate (!) a few chapters to that very topic. There has to be a reason…
The thing about memory allocation is that there’s no perfect solution to the problem in general; there are many good solutions on average, and there are very good solutions to more specialized versions of the problem. What constitutes a good solution for a given use case in programming language A might be inappropriate for another use case or in programming language B.
Take, for example, languages where is it idiomatic to allocate dynamically large numbers of small objects, something customary of Java or C#. In...