Concrete test allocator that tracks memory usage for testing.
Synopsis
Declared in <bslma_testallocator.h>
class TestAllocator
: public Allocator
Description
This class defines a concrete "test" allocator mechanism that implements the Allocator protocol, and provides instrumentation to track (1) the number of blocks/bytes currently in use, (2) the maximum number of blocks/bytes that have been outstanding at any one time, and (3) the cumulative number of blocks/bytes that have ever been allocated by this test allocator object. The accumulated statistics are based solely on the number of bytes requested. Additional testing facilities include allocation limits, verbosity modes, status, and automated report printing.
Note that, unlike many other allocators, this allocator does NOT rely on the currently installed default allocator (see bslma_default), but instead ‐‐ by default ‐‐ uses the MallocFreeAllocator singleton, which in turn calls the C Standard Library functions malloc and free as needed. Clients may, however, override this allocator by supplying (at construction) any other allocator implementing the Allocator protocol.
Base Classes
Name |
Description |
Pure abstract protocol for clients and suppliers of raw memory. |
Type Aliases
Name |
Description |
Alias for an unsigned integral type capable of representing the number of bytes in this platform's virtual address space. |
Member Functions
Name |
Description |
|
Constructors |
|
Destroy this allocator. |
Return a newly‐allocated block of memory of the specified |
|
Return the current number of allocation requests left before an exception is thrown. A negative value indicates that no exception is scheduled. |
|
Return the memory block at |
|
|
|
|
|
Return the current fill pattern value for this allocator. The behavior is undefined unless |
|
Return |
|
Return |
|
Return |
|
Return |
|
Return the allocated memory address of the most recent memory request. Return 0 if the request was invalid (e.g., allocate non‐ positive number of bytes). |
|
Return the number of bytes of the most recent memory request. Note that this number is always recorded regardless of the validity of the request. |
|
Return the address that was returned by the most recent allocation request. Return 0 if the most recent allocation request was for 0 bytes. |
|
Return the number of bytes of the most recent allocation request. |
|
Return the memory address of the last memory deallocation request. Note that the address is always recorded regardless of the validity of the request. |
|
Return the number of bytes of the most recent deallocation request. |
|
Return the address supplied to the most recent deallocation request. |
|
Return the number of bytes of the most recent deallocation request. |
|
Return the name of this test allocator, or 0 if no name was specified at construction. |
|
Return the cumulative number of allocation requests. |
|
Return the cumulative number of allocation requests. Note that this number is incremented for every |
|
Return the number of blocks currently allocated from this object. Note that |
|
Return the maximum number of blocks ever allocated from this object at any one time. Note that |
|
Return the cumulative number of blocks ever allocated from this object. Note that |
|
Return the number of times memory deallocations have detected that pad areas at the front or back of the user segment had been overwritten. |
|
Return the number of bytes currently allocated from this object. Note that |
|
Return the maximum number of bytes ever allocated from this object at any one time. Note that |
|
Return the cumulative number of bytes ever allocated from this object. Note that |
|
Return the cumulative number of deallocation requests. |
|
Return the cumulative number of deallocation requests. |
|
Return the number of mismatched memory deallocations. |
|
Write the accumulated state information held in this allocator to the optionally specified file |
|
Restore statistics previously saved by |
|
Set the allocation limit before an exception is thrown to |
|
Set the fill pattern for newly allocated memory to |
|
Set the no‐abort mode for this test allocator to |
|
Set the quiet mode for this test allocator to |
|
Set the verbose mode for this test allocator to |
|
Return the current statistics that may later be passed to |
|
Return a status code summarizing mismatches and outstanding memory. |
|
Unset the fill pattern for this test allocator. After calling this method, newly allocated memory will not be initialized with any fill pattern. |
Static Member Functions
Name |
Description |
Throw |
Protected Member Functions
Name |
Description |
|
Return a newly allocated block of at least |
|
Return the memory block at |
|
Return whether this allocator can exchange memory with |
Friends
Name |
Description |
Write the state of |
Non-Member Functions
Name |
Description |
Return |
|
Return |
Created with MrDocs