Logo Data Structures and Algorithms with Object-Oriented Design Patterns in C++
next up previous contents index

Implementation

The class BuddyPool is declared in Program gif. 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.

   program31910
Program: BuddyPool Class Definition

The nested structures Header and Block implement the layout given in Figure gif. 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.,

displaymath68239

which on a 32-bit machine is typically 12 bytes. In the BuddyPool implementation given in Program gif, the size of the Block structure is set to 16 bytes.




next up previous contents index

Bruno Copyright © 1997 by Bruno R. Preiss, P.Eng. All rights reserved.