-
Book Overview & Buying
-
Table Of Contents
C++ Memory Management
By :
So far in this book, including this chapter, we have stated that operator new() and operator new[]() typically throw std::bad_alloc when failing to allocate memory. It’s true to a wide extent, but there is a subtlety we have avoided so far and to which we will now give some time and attention.
Imagine a situation where user code has specialized the memory allocation functions to fetch memory blocks from a pre-allocated data structure with interesting performance characteristics. Suppose that this data structure initially allocates space for a small number of blocks and then goes on to allocate more space once the user code exhausts the blocks from the initial allocation. Expressed otherwise: in this situation, we have an initial, fast setting (let’s call that the “optimistic” state) and a secondary setting (let’s call that the “second chance” state) that lets user code continue allocating once...