[#BloombergLP-bdlma-CountingAllocator] = xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bdlma.adoc[bdlma]::CountingAllocator :relfileprefix: ../../ :mrdocs: Concrete allocator that counts bytes currently in use and ever allocated. == Synopsis Declared in `<bdlma_countingallocator.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- class CountingAllocator : public xref:BloombergLP/bslma/Allocator.adoc[bslma::Allocator] ---- == Description 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`). Note that, like many other allocators, this allocator relies on the currently installed default allocator (see `bslma_default`). Clients may, however, override this allocator by supplying (at construction) any other allocator implementing the `bslma::Allocator` protocol provided that it is fully thread‐safe. == Base Classes [cols="1,4"] |=== | Name| Description | `xref:BloombergLP/bslma/Allocator.adoc[bslma::Allocator]` | Pure abstract protocol for clients and suppliers of raw memory. |=== == Type Aliases [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bslma/Allocator/size_type.adoc[`size_type`] | Alias for an unsigned integral type capable of representing the number of bytes in this platform's virtual address space. |=== == Member Functions [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bdlma/CountingAllocator/2constructor-09.adoc[`CountingAllocator`] [.small]#[constructor]# | Constructors | xref:BloombergLP/bdlma/CountingAllocator/2destructor.adoc[`~CountingAllocator`] [.small]#[destructor]# [.small]#[virtual]# | Destroy this allocator object. Note that destroying this allocator has no effect on any outstanding allocated memory. | xref:BloombergLP/bslma/Allocator/operator_assign.adoc[`operator=`] | | xref:BloombergLP/bdlma/CountingAllocator/allocate-04.adoc[`allocate`] | `allocate` overloads | xref:BloombergLP/bdlma/CountingAllocator/deallocate-0d.adoc[`deallocate`] | Return the memory block at the specified `address` back to this allocator. | xref:BloombergLP/bslma/Allocator/deleteObject-09.adoc[`deleteObject`] | `deleteObject` overloads | xref:BloombergLP/bslma/Allocator/deleteObjectRaw-06f.adoc[`deleteObjectRaw`] | `deleteObjectRaw` overloads | xref:BloombergLP/bslma/Allocator/is_equal.adoc[`is_equal`] | | xref:BloombergLP/bdlma/CountingAllocator/name.adoc[`name`] | Return the name of this counting allocator, or 0 if no name was specified at construction. | xref:BloombergLP/bdlma/CountingAllocator/numBytesInUse.adoc[`numBytesInUse`] | Return the number of bytes currently allocated from this object. Note that `numBytesInUse() <= numBytesTotal()`. | xref:BloombergLP/bdlma/CountingAllocator/numBytesTotal.adoc[`numBytesTotal`] | Return the cumulative number of bytes ever allocated from this object. Note that `numBytesInUse() <= numBytesTotal()`. | xref:BloombergLP/bdlma/CountingAllocator/print.adoc[`print`] | 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`. |=== == Static Member Functions [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bslma/Allocator/throwBadAlloc.adoc[`throwBadAlloc`] | Throw `std::bad_alloc` or abort the program. |=== == Protected Member Functions [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bslma/Allocator/do_allocate.adoc[`do_allocate`] [.small]#[virtual]# | Return a newly allocated block of at least `bytes` with `alignment`. | xref:BloombergLP/bslma/Allocator/do_deallocate.adoc[`do_deallocate`] [.small]#[virtual]# | Return the memory block at `p` having `bytes` and `alignment`. | xref:BloombergLP/bslma/Allocator/do_is_equal.adoc[`do_is_equal`] [.small]#[virtual]# | Return whether this allocator can exchange memory with `other`. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#