Quick Links: |
#include <bslma_mallocfreeallocator.h>
Public Types | |
typedef bsls::Types::size_type | size_type |
Public Member Functions | |
MallocFreeAllocator () | |
virtual | ~MallocFreeAllocator () |
virtual void * | allocate (size_type size) |
virtual void | deallocate (void *address) |
template<class TYPE > | |
void | deleteObject (const TYPE *object) |
void | deleteObject (bsl::nullptr_t) |
template<class TYPE > | |
void | deleteObjectRaw (const TYPE *object) |
void | deleteObjectRaw (bsl::nullptr_t) |
Static Public Member Functions | |
static MallocFreeAllocator & | singleton () |
static void | throwBadAlloc () |
This class provides direct access to the system-supplied (native) global std::malloc
and std::free
. A static
method is provided for obtaining a unique, process wide object of this class, which is valid from the time the method is called until after the program (not just main
) exits.
See Component bslma_mallocfreeallocator
typedef bsls::Types::size_type bslma::Allocator::size_type [inherited] |
Reimplemented in bdlma::ConcurrentPoolAllocator.
bslma::MallocFreeAllocator::MallocFreeAllocator | ( | ) |
Create an allocator that uses std::malloc
and std::free
to supply memory. Note that all objects of this class share the same underlying resource.
virtual bslma::MallocFreeAllocator::~MallocFreeAllocator | ( | ) | [virtual] |
Destroy this allocator. Note that the behavior of destroying an allocator while memory is allocated from it is not specified. (Unless you know that it is valid to do so, don't!)
For this concrete implementation, destroying this allocator object has no effect on allocated memory.
static MallocFreeAllocator& bslma::MallocFreeAllocator::singleton | ( | ) | [static] |
Return a reference to a valid object of this class. Note that this object is guaranteed to be valid from the time of this call onward (i.e., not just until exiting main
).
virtual void* bslma::MallocFreeAllocator::allocate | ( | size_type | size | ) | [virtual] |
Return a newly allocated block of memory of (at least) the specified positive size
(in bytes). If size
is 0, a null pointer is returned with no other effect. If this allocator cannot return the requested number of bytes, then it will return a null pointer. The behavior is undefined unless 0 <= size
. Note that the alignment of the address returned is the maximum alignment for any type defined on this platform. Also note that std::malloc
is not called when size
is 0 (in order to avoid having to acquire a lock, and potential contention in multi-treaded programs).
Implements bslma::Allocator.
virtual void bslma::MallocFreeAllocator::deallocate | ( | void * | address | ) | [virtual] |
Return the memory block at the specified address
back to this allocator. If address
is 0, this function has no effect. The behavior is undefined unless address
was allocated using this allocator object and has not already been deallocated. Note that std::free
is not called when address
is 0 (in order to avoid having to acquire a lock, and potential contention in multi-treaded programs).
Implements bslma::Allocator.
static void bslma::Allocator::throwBadAlloc | ( | ) | [static, inherited] |
DEPRECATED: Use bsls::BslExceptionUtil::throwBadAlloc
instead.
Throw std::bad_alloc
if exceptions are enabled or abort the program otherwise. Derived classes and helper functions will typically call this function when they are unable to satisfy an allocation request. This function never returns.
void bslma::Allocator::deleteObject | ( | const TYPE * | object | ) | [inherited] |
Destroy the specified object
based on its dynamic type and then use this allocator to deallocate its memory footprint. Do nothing if object
is a null pointer. The behavior is undefined unless object
, when cast appropriately to void *
, was allocated using this allocator and has not already been deallocated. Note that dynamic_cast<void *>(object)
is applied if TYPE
is polymorphic, and static_cast<void *>(object)
is applied otherwise.
void bslma::Allocator::deleteObject | ( | bsl::nullptr_t | ) | [inherited] |
This function has no effect. Note that it exists to support calling deleteObject
will a null pointer literal, that would otherwise not deduce to a pointer type for the method above. As calls to deleteObject
with (typed) null pointer values have well-defined behavior, it should also support calls with a null pointer literal.
void bslma::Allocator::deleteObjectRaw | ( | const TYPE * | object | ) | [inherited] |
Destroy the specified object
and then use this allocator to deallocate its memory footprint. Do nothing if object
is a null pointer. The behavior is undefined unless object
was allocated using this allocator, is not a secondary base class pointer -- i.e., the address is (numerically) the same as when it was originally dispensed by this allocator, and has not already been deallocated.
void bslma::Allocator::deleteObjectRaw | ( | bsl::nullptr_t | ) | [inherited] |
This function has no effect. Note that it exists to support calling deleteObjectRaw
will a null pointer literal, that would otherwise not deduce to a pointer type for the method above. As calls to deleteObjectRaw
with (typed) null pointer values have well-defined behavior, it should also support calls with a null pointer literal.