BDE 4.14.0 Production release
|
Support memory allocation directly from virtual memory.
The bdlma::HeapBypassAllocator
class provided by this component implements a concrete allocator derived from the bslma::Allocator
interface that allocates memory directly from virtual memory, bypassing the heap. Reserves virtual memory in chunks so as to grow infrequently. The chunk size can optionally be chosen by providing an argument for replenishHint
in the constructor (see documentation for the constructor for advice on how to choose a good value for replenishHint
). All memory allocated by this allocator is freed when the allocator's destructor is called, but not before. A natural use case is for backing large, long-lived object pools, or cases where the heap may be corrupt.
This section illustrates intended use of this component.
Here we allocate some memory using a heap bypass allocator, then write to that memory, then read from it and verify the values written are preserved.
First, we allocate some segments:
Next, we write to the segments:
Finally, we read from the segments and verify the written data is still there:
Memory is released upon destruction of object hbpa
when it goes out of scope.