November 1999
Intermediate to advanced
336 pages
6h 29m
English
To avoid frequent hits to the default manager, the Rational class will maintain a static linked list of preallocated Rational objects, which will serve as the free list of available objects. When we need a new Rational object, we will get one from the free list. When we are done with an object, we will return it to the free list for future allocations.
We declare a helper structure to link adjacent elements on the free list.
class NextOnFreeList {
public:
NextOnFreeList *next;
};
The free list is declared as a linked list of NextOnFreeList elements.
class Rational {
...
static NextOnFreeList *freeList;
};
If the free list is a list of NextOnFreeList structures, you may wonder where the Rational ...
Read now
Unlock full access