|
BDE 4.14.0 Production release
|
Typedefs | |
| typedef bslma::MallocFreeAllocator | bslma_MallocFreeAllocator |
| This alias is defined for backward compatibility. | |
Provide malloc/free adaptor to bslma::Allocator protocol.
This component provides an allocator, bslma::MallocFreeAllocator, that implements the bslma::Allocator protocol and supplies memory using the system-supplied (native) std::malloc and std::free operators.
The key purpose of this component is to facilitate the use of malloc and free when the default bslma::NewDeleteAllocator is not desirable (such as the case of bslma::TestAllocator). To accomplish this goal, malloc and free are wrapped in a singleton object whose lifetime is guaranteed to exceed any possibility of its use.
A single object of bslma::MallocFreeAllocator is safe for concurrent access by multiple threads. The underlying implementation of malloc and free will ensure that heap corruption does not occur. Note that this allocator therefore has a stronger thread safety guarantee than is required by the base-class contract or than is provided by other allocators.
This component is intended to be used when the use of new and delete are not desirable, such as the case of bslma::TestAllocator. Instead of using bslma::Default which uses the bslma::NewDeleteAllocator, this component can be used to bypass the use of new and delete.
The following example demonstrates the use of this component for a user defined allocator instead of using the default allocator:
The constructor is implemented using bslma::MallocFreeAllocator.
When the basicAllocator is not specified, the bslma::MallocFreeAllocator will be used. That allocator then then calls std::malloc and std::free for allocating and deallocating memory.