BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslma::NewDeleteAllocator Class Reference

#include <bslma_newdeleteallocator.h>

Inheritance diagram for bslma::NewDeleteAllocator:
bslma::Allocator bsl::memory_resource

Public Member Functions

 NewDeleteAllocator ()
 
 ~NewDeleteAllocator () BSLS_KEYWORD_OVERRIDE
 
void * allocate (size_type size) BSLS_KEYWORD_OVERRIDE
 
void deallocate (void *address) BSLS_KEYWORD_OVERRIDE
 
- Public Member Functions inherited from bslma::Allocator
 ~Allocator () BSLS_KEYWORD_OVERRIDE
 
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)
 
- Public Member Functions inherited from bsl::memory_resource
 memory_resource () BSLS_KEYWORD_DEFAULT
 Create this object. Has no effect other than to begin its lifetime.
 
 memory_resource (const memory_resource &) BSLS_KEYWORD_DEFAULT
 
virtual ~memory_resource ()
 Destroy this object. Has no effect other than to end its lifetime.
 
memory_resourceoperator= (const memory_resource &) BSLS_KEYWORD_DEFAULT
 Return a modifiable reference to this object.
 
BSLS_ANNOTATION_NODISCARD void * allocate (size_t bytes, size_t alignment=k_MAX_ALIGN)
 
void deallocate (void *p, size_t bytes, size_t alignment=k_MAX_ALIGN)
 
bool is_equal (const memory_resource &other) const BSLS_KEYWORD_NOEXCEPT
 

Static Public Member Functions

static NewDeleteAllocatorsingleton ()
 
static Allocatorallocator (Allocator *basicAllocator)
 
- Static Public Member Functions inherited from bslma::Allocator
static void throwBadAlloc ()
 

Additional Inherited Members

- Public Types inherited from bslma::Allocator
typedef std::size_t size_type
 
- Protected Member Functions inherited from bslma::Allocator
void * do_allocate (std::size_t bytes, std::size_t alignment) BSLS_KEYWORD_OVERRIDE
 
void do_deallocate (void *p, std::size_t bytes, std::size_t alignment) BSLS_KEYWORD_OVERRIDE
 
bool do_is_equal (const memory_resource &other) const BSLS_KEYWORD_NOEXCEPT BSLS_KEYWORD_OVERRIDE
 

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 bslma_newdeleteallocator

Constructor & Destructor Documentation

◆ NewDeleteAllocator()

bslma::NewDeleteAllocator::NewDeleteAllocator ( )
inline

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).

◆ ~NewDeleteAllocator()

bslma::NewDeleteAllocator::~NewDeleteAllocator ( )

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

Member Function Documentation

◆ allocate()

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.

◆ allocator()

Allocator * bslma::NewDeleteAllocator::allocator ( Allocator basicAllocator)
inlinestatic

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
static 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).

◆ deallocate()

void bslma::NewDeleteAllocator::deallocate ( void *  address)
inlinevirtual

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.

◆ singleton()

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).


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