BDE 4.14.0 Production release
|
Provide allocation and management of infrequently deleted blocks.
This component implements a low-level memory manager, bdlma::InfrequentDeleteBlockList
, 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::InfrequentDeleteBlockList
object deallocates the entire sequence of outstanding memory blocks, as does its destructor. Note that, in contrast to bdlma::BlockList
, the bdlma::InfrequentDeleteBlockList
class does not support the deallocation of individual items. In particular, although bdlma::InfrequentDeleteBlockList
has a deallocate
method, that method has no effect.
This section illustrates intended use of this component.
A bdlma::InfrequentDeleteBlockList
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::InfrequentDeleteBlockList
object. The my_StrPool
memory pool manager shown below requests relatively large blocks of memory from its bdlma::InfrequentDeleteBlockList
member object and distributes memory chunks of varying sizes from each block on demand:
In the code shown above, the my_StrPool
memory manager allocates from its bdlma::InfrequentDeleteBlockList
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 (1) is not available in the current block, or (2) exceeds the k_THRESHOLD
, in which case a separate memory block is allocated and returned. When the my_StrPool
memory manager is destroyed, its bdlma::InfrequentDeleteBlockList
member object is also destroyed, which in turn automatically deallocates all of its managed memory blocks.