Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Static Public Member Functions | List of all members
Teuchos::Details::AllocationLogger Class Reference

Logging implementation used by Allocator (see below). More...

#include <Teuchos_Details_Allocator.hpp>

Public Types

typedef std::size_t size_type
 Type of the size of an allocation or deallocation. More...
 

Static Public Member Functions

static void logAllocation (std::ostream &out, const size_type numEntries, const size_type numBytes, const char typeName[], const bool verbose)
 Log an allocation. More...
 
static void logDeallocation (std::ostream &out, const size_type numEntries, const size_type numBytes, const char typeName[], const bool verbose)
 Log a deallocation, that was previously logged using logAllocation(). More...
 
static size_type curAllocInBytes ()
 Current total allocation in bytes. More...
 
static size_type maxAllocInBytes ()
 Max total allocation ("high water mark") in bytes. More...
 
static void resetAllocationCounts ()
 Reset the current and max total allocation numbers to zero. More...
 

Detailed Description

Logging implementation used by Allocator (see below).

Warning
This is an implementation detail of Teuchos. We make no promises of backwards compatibility for this header file or this class. They may change or disappear at any time.

Please refer to teuchos/core/test/HashTable/Allocator_atexit.cpp for an example of how to register an atexit() hook that reports current and maximum memory usage at exit from main(). It would be easy to adapt this example to register an MPI_Finalize() hook, using the MPI standard idiom of attaching an attribute to MPI_COMM_SELF.

Definition at line 75 of file Teuchos_Details_Allocator.hpp.

Member Typedef Documentation

Type of the size of an allocation or deallocation.

This must match Allocator::size_type (see below).

Definition at line 80 of file Teuchos_Details_Allocator.hpp.

Member Function Documentation

void Teuchos::Details::AllocationLogger::logAllocation ( std::ostream &  out,
const size_type  numEntries,
const size_type  numBytes,
const char  typeName[],
const bool  verbose 
)
static

Log an allocation.

This is useful for Allocator<T>, but not so useful for users, unless they are writing a custom Allocator and want it use this class for logging.

Parameters
out[out] Output stream to which to write logging information, if verbose is true.
numEntries[in] Number of entries (of type T) in the allocated array (1 if just allocating one instance of T).
numBytes[in] Number of bytes in the allocated array. This would normally be numEntries*sizeof(T), at least for types T which are "plain old data" (POD) or structs thereof. We make you compute this, so that the logger doesn't have to know about (e.g., be templated on) the type T.
typeName[in] Human-readable name of the type T, for which you are logging an allocation.
verbose[in] Whether to print logging information to the given output stream out.

Definition at line 50 of file Teuchos_Details_Allocator.cpp.

void Teuchos::Details::AllocationLogger::logDeallocation ( std::ostream &  out,
const size_type  numEntries,
const size_type  numBytes,
const char  typeName[],
const bool  verbose 
)
static

Log a deallocation, that was previously logged using logAllocation().

This is useful for Allocator<T>, but not so useful for users, unless they are writing a custom Allocator and want it use this class for logging.

Parameters
out[out] Output stream to which to write logging information, if verbose is true.
numEntries[in] Number of entries (of type T) in the deallocated array (1 if just allocating one instance of T). Note that the allocate() function in the C++ Standard Library's Allocator concept gets this information, unlike free() or operator delete[].
numBytes[in] Number of bytes in the deallocated array. This would normally be numEntries*sizeof(T), at least for types T which are "plain old data" (POD) or structs thereof. We make you compute this, so that the logger doesn't have to know about (e.g., be templated on) the type T.
typeName[in] Human-readable name of the type T, for which you are logging a deallocation.
verbose[in] Whether to print logging information to the given output stream out.

Definition at line 70 of file Teuchos_Details_Allocator.cpp.

AllocationLogger::size_type Teuchos::Details::AllocationLogger::curAllocInBytes ( )
static

Current total allocation in bytes.

This count includes allocations using Allocator<T> for all T.

Definition at line 91 of file Teuchos_Details_Allocator.cpp.

AllocationLogger::size_type Teuchos::Details::AllocationLogger::maxAllocInBytes ( )
static

Max total allocation ("high water mark") in bytes.

This count includes allocations using Allocator<T> for all T.

Definition at line 94 of file Teuchos_Details_Allocator.cpp.

void Teuchos::Details::AllocationLogger::resetAllocationCounts ( )
static

Reset the current and max total allocation numbers to zero.

This is mainly helpful just for tests.

Definition at line 97 of file Teuchos_Details_Allocator.cpp.


The documentation for this class was generated from the following files: