The class BuddyPool is declared in Program . BuddyPool is a concrete class derived from the abstract base class StoragePool. The public interface includes a constructor, a destructor, and the member functions Acquire and Release. Three additional private member functions, Buddy, Unlink and InsertAfter are declared.
Program: BuddyPool Class Definition
The nested structures Header and Block implement the layout given in Figure . The Header contains fields which are used in the representation of both reserved and free areas. A Header comprises the two members status and k. The former is a one-bit field of type Status. The latter encodes the length of the block as described above.
The Block structure contains a union that overlays an instance of the structure Links with the userPart of the block. If the block is a free block, the contents of the Links structure are used to link the associated area in the appropriate free list. If the block is reserved, the space in the userPart has been allocated to the user.
The minimum size of a block is the same as for the DoublyLinkedPool class, viz.,
which on a 32-bit machine is typically 12 bytes. In the BuddyPool implementation given in Program , the size of the Block structure is set to 16 bytes.