Quick Links:

bal | bbl | bdl | bsl

Public Types | Public Member Functions | Static Public Member Functions

bslma::Allocator Class Reference

#include <bslma_allocator.h>

Inheritance diagram for bslma::Allocator:
bslma::AllocatorAdaptor_Imp< STL_ALLOC::template rebind< char >::other > ball::CountingAllocator bdlma::AlignedAllocator bdlma::AligningAllocator bdlma::ConcurrentAllocatorAdapter bdlma::ConcurrentPoolAllocator bdlma::CountingAllocator bdlma::GuardingAllocator bdlma::HeapBypassAllocator bdlma::ManagedAllocator bslma::AllocatorAdaptor_Imp< STL_ALLOC > bslma::BufferAllocator bslma::MallocFreeAllocator bslma::ManagedAllocator bslma::NewDeleteAllocator bslma::TestAllocator

List of all members.

Public Types

typedef bsls::Types::size_type size_type

Public Member Functions

virtual ~Allocator ()
virtual void * allocate (size_type size)=0
virtual void deallocate (void *address)=0
template<class TYPE >
void deleteObject (const TYPE *object)
template<class TYPE >
void deleteObjectRaw (const TYPE *object)
void deleteObject (bsl::nullptr_t)
void deleteObjectRaw (bsl::nullptr_t)

Static Public Member Functions

static void throwBadAlloc ()

Detailed Description

This protocol class provides a pure abstract interface and contract for clients and suppliers of raw memory. If the requested memory cannot be returned, the contract requires that an std::bad_alloc exception be thrown. Note that memory is guaranteed to be sufficiently aligned for any object of the requested size on the current platform, which may be less than the maximal alignment guarantee afforded by global operator new.

See Component bslma_allocator


Member Typedef Documentation


Constructor & Destructor Documentation

virtual bslma::Allocator::~Allocator (  )  [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!)


Member Function Documentation

static void bslma::Allocator::throwBadAlloc (  )  [static]

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.

virtual void* bslma::Allocator::allocate ( size_type  size  )  [pure 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 throw a std::bad_alloc exception in an exception-enabled build, or else will abort the program in a non-exception build. The behavior is undefined unless 0 <= size. Note that the alignment of the address returned conforms to the platform requirement for any object of the specified size.

Implemented in ball::CountingAllocator, balst::StackTraceTestAllocator, bdlma::BufferedSequentialAllocator, bslma::AllocatorAdaptor_Imp< STL_ALLOC >, bslma::BufferAllocator, bslma::MallocFreeAllocator, bslma::NewDeleteAllocator, bslma::SequentialAllocator, bslma::TestAllocator, and bslma::AllocatorAdaptor_Imp< STL_ALLOC::template rebind< char >::other >.

virtual void bslma::Allocator::deallocate ( void *  address  )  [pure virtual]
template<class TYPE >
void bslma::Allocator::deleteObject ( const TYPE *  object  ) 

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.

template<class TYPE >
void bslma::Allocator::deleteObjectRaw ( const TYPE *  object  ) 

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::deleteObject ( bsl::nullptr_t   ) 

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 ( bsl::nullptr_t   ) 

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.


The documentation for this class was generated from the following file: