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.
Synopsis
Declared in <bslma_testallocator.h>
class TestAllocator
: public Allocator
Description
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 |
This protocol class provides a pure abstract interface and contract for clients and suppliers of raw memory. If the requested memory cannot be returned, the contract requires that an |
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. In verbose mode, print all contained state values of this allocator object to |
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 the specified |
|
|
|
|
|
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 memory deallocation request. Return 0 if the request was invalid (e.g., deallocating memory not allocated through this allocator). |
|
Return the address that was supplied to the most recent deallocation request. Return 0 if a null pointer was most recently deallocated. 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 0 if a null pointer was most recently deallocated, or if the request was invalid (e.g., an attempt to deallocate memory not allocated through this allocator). |
|
Return the name of this test allocator, or 0 if no name was specified at construction. |
|
Return the cumulative number of allocation requests. Note that this number is incremented for every |
|
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. Note that this number is incremented for every |
|
Return the cumulative number of deallocation requests. Note that this number is incremented for every |
|
Return the number of mismatched memory deallocations that have occurred since this object was created. A memory deallocation is mismatched if that memory was not allocated directly from this allocator. |
|
Write the accumulated state information held in this allocator to the optionally specified file |
|
Restore the statistics from the specified |
|
Set the number of valid allocation requests before an exception is to be thrown for this allocator to the specified |
|
Set the fill pattern for this test allocator to the specified 64‐bit |
|
Set the no‐abort mode for this test allocator to the specified (boolean) |
|
Set the quiet mode for this test allocator to the specified (boolean) |
|
Set the verbose mode for this test allocator to the specified (boolean) |
|
Return the current statistics that may later be passed to |
|
Return 0 on success, and non‐zero otherwise: If there have been any mismatched memory deallocations or over/under runs, return the number of such errors that have occurred as a positive number; if either |
|
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 memory of (at least) the specified positive |
|
Return the memory block at the specified |
|
Return |
Friends
Name |
Description |
Write the accumulated state information held in the specified allocator |
Non-Member Functions
Name |
Description |
Return |
|
Return |
Created with MrDocs