BDE 4.14.0 Production release
Loading...
Searching...
No Matches
ball::CountingAllocator Class Reference

#include <ball_countingallocator.h>

Inheritance diagram for ball::CountingAllocator:
bslma::Allocator bsl::memory_resource

Public Member Functions

 CountingAllocator (bslma::Allocator *basicAllocator=0)
 
 ~CountingAllocator () BSLS_KEYWORD_OVERRIDE
 Destroy this counting allocator.
 
void * allocate (size_type size) BSLS_KEYWORD_OVERRIDE
 
void deallocate (void *address) BSLS_KEYWORD_OVERRIDE
 
void resetNumBytesTotal ()
 Reset the byte count maintained by this counting allocator to 0.
 
size_type numBytesTotal () const
 
- 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
 

Additional Inherited Members

- Public Types inherited from bslma::Allocator
typedef std::size_t size_type
 
- Static Public Member Functions inherited from bslma::Allocator
static void throwBadAlloc ()
 
- 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 maintains a count of the total number of allocated bytes. The running byte count is initialized to 0 upon construction, is increased by the allocate method, and may be reset to 0 by the resetNumBytesTotal method. The deallocate method appropriately decrement the byte count. The precise definition of byte count is described in the "Byte Count" section of the component-level documentation.

See ball_countingallocator

Constructor & Destructor Documentation

◆ CountingAllocator()

ball::CountingAllocator::CountingAllocator ( bslma::Allocator basicAllocator = 0)
inlineexplicit

Create a counting allocator having an initial byte count of 0. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.

◆ ~CountingAllocator()

ball::CountingAllocator::~CountingAllocator ( )

Member Function Documentation

◆ allocate()

void * ball::CountingAllocator::allocate ( size_type  size)
inlinevirtual

Return a newly allocated block of memory of (at least) the specified positive size (bytes) and increment the byte count maintained by this counting allocator by the sum of the least multiple of bsls::AlignmentUtil::BSLS_MAX_ALIGNMENT that is greater than or equal to size and bsls::AlignmentUtil::BSLS_MAX_ALIGNMENT. The behavior is undefined unless 0 <= size. Note that the alignment of the address returned is the maximum alignment for any fundamental type defined for the calling platform, even if the supplied allocator guarantees only natural alignment.

Implements bslma::Allocator.

◆ deallocate()

void ball::CountingAllocator::deallocate ( void *  address)
inlinevirtual

Return the memory at the specified address back to this allocator and update the byte count maintained by this counting allocator appropriately. If address is 0, this function has no effect. The behavior is undefined unless address was allocated using this allocator and has not already been deallocated.

Implements bslma::Allocator.

◆ numBytesTotal()

CountingAllocator::size_type ball::CountingAllocator::numBytesTotal ( ) const
inline

Return the byte count maintained by this counting allocator. The precise definition of byte count is described in the "Byte Count" section of the component-level documentation.

◆ resetNumBytesTotal()

void ball::CountingAllocator::resetNumBytesTotal ( )
inline

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