This class maintains a count of the total number of allocated bytes.

Synopsis

Declared in <ball_countingallocator.h>

class CountingAllocator
    : public bslma::Allocator

Description

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.

Base Classes

Name

Description

bslma::Allocator

Pure abstract protocol for clients and suppliers of raw memory.

Type Aliases

Name

Description

size_type

Alias for an unsigned integral type capable of representing the number of bytes in this platform's virtual address space.

Member Functions

Name

Description

CountingAllocator [constructor]

Create a counting allocator having an initial byte count of 0.

~CountingAllocator [destructor] [virtual]

Destroy this counting allocator.

operator=

allocate

Allocate a maximally aligned block of the specified size.

deallocate

Return the memory at the specified address to this allocator.

deleteObject

deleteObject overloads

deleteObjectRaw

deleteObjectRaw overloads

is_equal

numBytesTotal

Return the byte count maintained by this counting allocator.

resetNumBytesTotal

Reset the byte count maintained by this counting allocator to 0.

Static Member Functions

Name

Description

throwBadAlloc

Throw std::bad_alloc or abort the program.

Protected Member Functions

Name

Description

do_allocate [virtual]

Return a newly allocated block of at least bytes with alignment.

do_deallocate [virtual]

Return the memory block at p having bytes and alignment.

do_is_equal [virtual]

Return whether this allocator can exchange memory with other.

Created with MrDocs