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

Optional tracking allocator for Teuchos Memory Management classes. More...

#include <Teuchos_Details_Allocator.hpp>

Classes

struct  rebind
 Mapping to an Allocator for a different type U. More...
 

Public Types

typedef T value_type
 Type of the template parameter of this class. More...
 
typedef T * pointer
 Type of a pointer to T. More...
 
typedef const T * const_pointer
 Type of a pointer to const T. More...
 
typedef T & reference
 Type of a reference to T. More...
 
typedef const T & const_reference
 Type of a reference to const T. More...
 
typedef AllocationLogger::size_type size_type
 Type of the size of an allocation or deallocation. More...
 
typedef std::ptrdiff_t difference_type
 Integer type representing the difference between two pointers. More...
 

Public Member Functions

 Allocator ()
 Default constructor. More...
 
 Allocator (const bool trackMemory, const bool verboseOutput)
 Constructor. More...
 
template<class U >
 Allocator (const Allocator< U > &src)
 Copy constructor that takes an Allocator<U> for any U. More...
 
size_type max_size () const
 Upper bound (possibly loose) on maximum allocation size. More...
 
value_typeallocate (const size_type &n, const void *=0)
 Allocate an array of n instances of value_type. More...
 
void deallocate (value_type *p, const size_type &n)
 Deallocate n instances of value_type. More...
 
size_type curAllocInBytes ()
 Current total allocation in bytes, over all Allocator<U>. More...
 
size_type maxAllocInBytes ()
 Max total allocation ("high water mark") in bytes, over all Allocator<U>. More...
 
void construct (pointer p, const_reference val)
 Invoke the constructor of an instance of T, without allocating. More...
 
void destroy (pointer p)
 Invoke the destructor of an instance of T, without deallocating. More...
 

Detailed Description

template<class T>
class Teuchos::Details::Allocator< T >

Optional tracking allocator for Teuchos Memory Management classes.

Template Parameters
TThe type of the entries in arrays to allocate.
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.

This class implements the C++ Standard Library's "Allocator" concept. It does "high water mark" tracking, and has the option to print to stderr on allocations and deallocations.

Note
To Teuchos developers: Making this class be the "allocator" (second) template parameter of the std::vector type that Teuchos::Array uses, would make Teuchos::Array track memory. (This would require changing Teuchos::Array.) It should also be possible to change Teuchos::ArrayRCP to use this class as well, but only to track memory that it allocates (vs. memory given it by the user, possibly with a custom deallocator functor).

Definition at line 156 of file Teuchos_Details_Allocator.hpp.

Member Typedef Documentation

template<class T>
typedef T Teuchos::Details::Allocator< T >::value_type

Type of the template parameter of this class.

Definition at line 178 of file Teuchos_Details_Allocator.hpp.

template<class T>
typedef T* Teuchos::Details::Allocator< T >::pointer

Type of a pointer to T.

This is only needed for C++98, not for C++11 and newer.

Definition at line 183 of file Teuchos_Details_Allocator.hpp.

template<class T>
typedef const T* Teuchos::Details::Allocator< T >::const_pointer

Type of a pointer to const T.

This is only needed for C++98, not for C++11 and newer.

Definition at line 187 of file Teuchos_Details_Allocator.hpp.

template<class T>
typedef T& Teuchos::Details::Allocator< T >::reference

Type of a reference to T.

This is only needed for C++98, not for C++11 and newer.

Definition at line 191 of file Teuchos_Details_Allocator.hpp.

template<class T>
typedef const T& Teuchos::Details::Allocator< T >::const_reference

Type of a reference to const T.

This is only needed for C++98, not for C++11 and newer.

Definition at line 195 of file Teuchos_Details_Allocator.hpp.

Type of the size of an allocation or deallocation.

This must match AllocationLogger::size_type (see above). If we didn't need this to have the same type as that, then we wouldn't need this typedef.

Definition at line 202 of file Teuchos_Details_Allocator.hpp.

Integer type representing the difference between two pointers.

This is only needed for C++98, not for C++11 and newer. However, we want this typedef to exist in both cases. Thus, if C++11 is enabled, we use size_type above to compute this, in order to ensure consistency.

Definition at line 214 of file Teuchos_Details_Allocator.hpp.

Constructor & Destructor Documentation

template<class T>
Teuchos::Details::Allocator< T >::Allocator ( )
inline

Default constructor.

Definition at line 218 of file Teuchos_Details_Allocator.hpp.

template<class T>
Teuchos::Details::Allocator< T >::Allocator ( const bool  trackMemory,
const bool  verboseOutput 
)
inline

Constructor.

Parameters
trackMemory[in] Whether to track memory usage at all. If false, verboseOutput is ignored.
verboseOutput[in] Whether to print on every allocation and deallocation. Even if this is true, trackMemory must also be true in order for this to work.

Definition at line 229 of file Teuchos_Details_Allocator.hpp.

template<class T>
template<class U >
Teuchos::Details::Allocator< T >::Allocator ( const Allocator< U > &  src)
inline

Copy constructor that takes an Allocator<U> for any U.

Definition at line 236 of file Teuchos_Details_Allocator.hpp.

Member Function Documentation

template<class T>
size_type Teuchos::Details::Allocator< T >::max_size ( ) const
inline

Upper bound (possibly loose) on maximum allocation size.

Implementations of the Allocator concept should not NEED this method, but it makes the Clang compiler happy.

Definition at line 256 of file Teuchos_Details_Allocator.hpp.

template<class T>
value_type* Teuchos::Details::Allocator< T >::allocate ( const size_type n,
const void *  = 0 
)
inline

Allocate an array of n instances of value_type.

Parameters
n[in] Number of entries in the array.

The optional second argument provides an "allocation hint." This implementation ignores the hint.

Returns
The allocated but uninitialized array.

Definition at line 268 of file Teuchos_Details_Allocator.hpp.

template<class T>
void Teuchos::Details::Allocator< T >::deallocate ( value_type p,
const size_type n 
)
inline

Deallocate n instances of value_type.

Parameters
p[in] Pointer to the array to deallocate.
n[in] Number of entries in the array p.

Definition at line 280 of file Teuchos_Details_Allocator.hpp.

template<class T>
size_type Teuchos::Details::Allocator< T >::curAllocInBytes ( )
inline

Current total allocation in bytes, over all Allocator<U>.

Definition at line 292 of file Teuchos_Details_Allocator.hpp.

template<class T>
size_type Teuchos::Details::Allocator< T >::maxAllocInBytes ( )
inline

Max total allocation ("high water mark") in bytes, over all Allocator<U>.

Definition at line 297 of file Teuchos_Details_Allocator.hpp.

template<class T>
void Teuchos::Details::Allocator< T >::construct ( pointer  p,
const_reference  val 
)
inline

Invoke the constructor of an instance of T, without allocating.

Warning
This variant only exists if C++11 is OFF. C++11 requires a method with a different signature, but it also supplies a good default implementation if this method is missing.
Parameters
p[in] Pointer to an area of memory in which to construct a T instance, using placement new.
val[in] Argument to T's (copy) constructor.

Definition at line 313 of file Teuchos_Details_Allocator.hpp.

template<class T>
void Teuchos::Details::Allocator< T >::destroy ( pointer  p)
inline

Invoke the destructor of an instance of T, without deallocating.

Warning
This variant only exists if C++11 is OFF. C++11 requires a method with a different signature, but it also supplies a good default implementation if this method is missing.
Parameters
p[in] Pointer to an instance of T to destroy.

Definition at line 328 of file Teuchos_Details_Allocator.hpp.


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