|
BDE 4.39.x Production Release
|
#include <bdlma_countingallocator.h>
This class defines a concrete "counting" allocator mechanism that implements the bslma::Allocator protocol, and provides instrumentation to track: (1) the number of bytes currently in use, and (2) the cumulative number of bytes that have ever been allocated. The accumulated statistics are based solely on the number of bytes requested (see allocate).
bslma::Allocator protocol provided that it is fully thread-safe.Public Member Functions | |
| CountingAllocator (bslma::Allocator *basicAllocator=0) | |
| CountingAllocator (const char *name, bslma::Allocator *basicAllocator=0) | |
| ~CountingAllocator () BSLS_KEYWORD_OVERRIDE | |
| void * | allocate (bsls::Types::size_type size) BSLS_KEYWORD_OVERRIDE |
| void | deallocate (void *address) BSLS_KEYWORD_OVERRIDE |
| const char * | name () const |
| bsls::Types::Int64 | numBytesInUse () const |
| bsls::Types::Int64 | numBytesTotal () const |
| bsl::ostream & | print (bsl::ostream &stream) 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 | |
| memory_resource (const memory_resource &) BSLS_KEYWORD_DEFAULT | |
| virtual | ~memory_resource () |
| memory_resource & | operator= (const memory_resource &) BSLS_KEYWORD_DEFAULT |
| BSLA_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 |
|
explicit |
Create a counting allocator. Optionally specify a name (associated with this object) to be included in messages output by the print method, thereby distinguishing this counting allocator from others that might be used in the same program. If name is 0 (or not specified), no distinguishing name is incorporated in print output. Optionally specify a basicAllocator used to supply memory. If basicAllocator is 0, the currently installed default allocator is used.
|
explicit |
| bdlma::CountingAllocator::~CountingAllocator | ( | ) |
Destroy this allocator object.
|
virtual |
Return a newly-allocated block of memory of the specified size (in bytes). If size is 0, a null pointer is returned with no other effect (e.g., on allocation statistics). Otherwise, invoke the allocate method of the allocator supplied at construction, and increment the number of currently (and cumulatively) allocated bytes by size.
Implements bslma::Allocator.
|
virtual |
Return the memory block at the specified address back to this allocator. If address is 0, this function has no effect (e.g., on allocation statistics). Otherwise, decrease the number of currently allocated bytes by the size originally requested for the block.
address was allocated using this allocator object and has not already been deallocated. Implements bslma::Allocator.
|
inline |
Return the name of this counting allocator, or 0 if no name was specified at construction.
|
inline |
Return the number of bytes currently allocated from this object.
numBytesInUse() <= numBytesTotal().
|
inline |
Return the cumulative number of bytes ever allocated from this object.
numBytesInUse() <= numBytesTotal(). | bsl::ostream & bdlma::CountingAllocator::print | ( | bsl::ostream & | stream | ) | const |
Write the accumulated state information held in this allocator to the specified stream in some reasonable (multi-line) format, and return a reference to stream.