Quick Links:

bal | bbl | bdl | bsl

Public Types | Public Member Functions | Static Public Member Functions

bslma::NewDeleteAllocator Class Reference

#include <bslma_newdeleteallocator.h>

Inheritance diagram for bslma::NewDeleteAllocator:
bslma::Allocator

List of all members.

Public Types

typedef bsls::Types::size_type size_type

Public Member Functions

 NewDeleteAllocator ()
virtual ~NewDeleteAllocator ()
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 NewDeleteAllocatorsingleton ()
static Allocatorallocator (Allocator *basicAllocator)
static void throwBadAlloc ()

Detailed Description

This class defines a concrete mechanism that adapts the system-supplied (native) global operator new and operator delete to the Allocator protocol. The class method singleton returns a process-wide unique object of this class whose lifetime is guaranteed to extend from the first call to singleton until the program terminates. A second class method, allocator, allows for conveniently replacing a "null" allocator with this singleton object. Note that this entire class should generally not be used directly by typical clients (see bslma_default for more information).

See Component bslma_newdeleteallocator


Member Typedef Documentation


Constructor & Destructor Documentation

bslma::NewDeleteAllocator::NewDeleteAllocator (  ) 

Create a ("stateless") new-delete-allocator object that wraps the global native operator new and operator delete functions in order to supply memory via the Allocator protocol. Note that all objects of this class share the same underlying resource; hence, this constructor should generally not be invoked directly by clients; instead, consider using the static singleton or allocator (factory) methods, or -- better -- the appropriate ones in Default (see bslma_default for more information).

virtual bslma::NewDeleteAllocator::~NewDeleteAllocator (  )  [virtual]

Destroy this allocator object. Note that destroying this allocator has no effect on any outstanding allocated memory.


Member Function Documentation

static NewDeleteAllocator& bslma::NewDeleteAllocator::singleton (  )  [static]

Return a reference to a process-wide unique object of this class. The lifetime of this object is guaranteed to extend from the first call of this method until the program terminates. Note that this method should generally not be used directly by typical clients (see bslma_default for more information).

static Allocator* bslma::NewDeleteAllocator::allocator ( Allocator basicAllocator  )  [static]

Return the address of the specified modifiable basicAllocator or, if basicAllocator is 0, the process-wide unique (see singleton) object of this class. Note that the behavior of this function is equivalent to the following expression:

          basicAllocator
          ? basicAllocator
          : &NewDeleteAllocator::singleton()

Also note that if a NewDeleteAllocator object is supplied, it is owned by the class and must NOT be deleted. Finally note that this method should generally not be called directly by typical clients (see bslma_default for more information).

virtual void* bslma::NewDeleteAllocator::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. The alignment of the address returned is the maximum alignment for any fundamental, pointer, or enumerated type defined for this platform. The behavior is undefined unless 0 <= size. Note that global operator new is not called when size is 0 (in order to avoid having to acquire a lock, and potential contention in multi-threaded programs).

Implements bslma::Allocator.

virtual void bslma::NewDeleteAllocator::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 global operator delete is not called when address is 0 (in order to avoid having to acquire a lock, and potential contention in multi-threaded 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.

template<class TYPE >
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.

template<class TYPE >
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.


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