BDE 4.14.0 Production release
|
Provide allocation and management of a sequence of memory blocks.
This component implements a low-level memory manager, bdlma::BlockList
, that allocates and manages a sequence of memory blocks, each of a potentially different size as specified during the allocate
method's invocation. The release
method of a bdlma::BlockList
object deallocates the entire sequence of outstanding memory blocks, as does its destructor. Note that a bdlma::BlockList
, at a minor memory expense, allows for individual items to be deallocated.
This section illustrates intended use of this component.
A bdlma::BlockList
object is commonly used to supply memory to more elaborate memory managers that distribute parts of each (larger) allocated memory block supplied by the bdlma::BlockList
object. The my_StrPool
memory pool manager shown below requests relatively large blocks of memory from its bdlma::BlockList
member object and distributes, via its allocate
method, memory chunks of varying sizes from each block.
First, we define the interface of our my_StrPool
class:
Finally, we provide the implementation of our my_StrPool
class:
In the code shown above, the my_StrPool
memory manager allocates from its bdlma::BlockList
member object an initial memory block of size k_INITIAL_SIZE
. This size is multiplied by k_GROWTH_FACTOR
each time a depleted memory block is replaced by a newly-allocated block. The allocate
method distributes memory from the current memory block piecemeal, except when the requested size either (1) is not available in the current block, or (2) exceeds the k_THRESHOLD_SIZE
, in which case a separate memory block is allocated and returned. When the my_StrPool
memory manager is destroyed, its bdlma::BlockList
member object is also destroyed, which, in turn, automatically deallocates all of its managed memory blocks.