mem Namespace Reference

Wrappers and tools for low-level memory management, including: More...

Functions

template<typename T >
T * Alloc ()
 Allocates a (debug) poisoned element.
template<typename T >
T * Alloc (size_t elems)
 Allocates a (debug) poisoned array, measured in elements.
template<typename T >
T * AllocBytes (size_t bytes)
 Allocates a (debug) poisoned array, measured in bytes.
template<typename T >
T * AllocConstruct (size_t elems=1)
 Allocates and default constructs an array.
template<typename T >
T * AllocCopy (const T *src, size_t elems=1)
template<typename T , typename U >
T * AllocCopy (const U *src, size_t elems=1)
 Allocates an array bit-copied from src, measured in elements.
template<typename T , typename U >
T * AllocCopyBytes (const U *src, size_t bytes)
 Allocates an array bit-copied from src, measured in bytes.
template<typename T >
T * AllocCopyConstruct (const T *src, size_t elems=1)
template<typename T , typename U >
T * AllocCopyConstruct (const U *src, size_t elems=1)
 Allocates and element-wise copy constructs an array.
template<typename T , typename U >
T * AllocCopyValues (const U *src, size_t elems=1)
template<typename T >
T * AllocRepeatConstruct (const T &init, size_t elems)
template<typename T , typename U >
T * AllocRepeatConstruct (const U &init, size_t elems)
 Allocates and copy constructs an array.
template<typename T >
T * AllocZero (size_t elems=1)
 Allocates a bit-zerod array, measured in elements.
template<typename T >
T * AllocZeroBytes (size_t bytes)
 Allocates a bit-zerod array, measured in bytes.
template<typename T >
T * BitCopy (T *dest, const T *src, size_t elems=1)
 Renamed Copy.
template<typename T , typename U >
T * BitCopyBytes (T *dest, const U *src, size_t bytes)
 Renamed CopyBytes.
template<typename T >
void BitSwap (T *a, T *b, size_t elems=1)
 Renamed Swap.
template<typename T >
T * BitZero (T *array, size_t elems=1)
 Renamed Zero.
template<typename T >
T * BitZeroBytes (T *array, size_t bytes)
 Renamed ZeroBytes.
template<typename T >
T ** Construct (T **array, size_t elems=1)
 No-op constructs an array of pointers.
template<typename T >
T * Construct (T *array, size_t elems)
 Default constructs each element in an array.
template<typename T >
T * Construct (T *ptr)
 Default Constructs An element.
template<typename T >
T * Copy (T *dest, const T *src, size_t elems=1)
template<typename V , typename T , typename U >
T * Copy (T *dest, const U *src, size_t elems=1)
 Bit-copies from src to dest, measured in elements.
template<typename T , typename U >
T * CopyBytes (T *dest, const U *src, size_t bytes)
 Bit-copies from src to dest, measured in bytes.
template<typename T >
T ** CopyConstruct (T **dest, const T **src, size_t elems=1)
 Bit-copy copy constructs an array of pointers.
template<typename T , typename U >
T * CopyConstruct (T *dest, const U *src, size_t elems)
 Element-wise copy constructs one array given another.
template<typename T , typename U >
T * CopyConstruct (T *dest, const U *src)
 Element-wise copy constructs one element given another.
template<typename T , typename U >
T * CopyValues (T *dest, const U *src, size_t elems=1)
template<typename T >
T * DebugPoison (T *ptr)
 Fills an element with BIG_BAD_NUMBER.
template<typename T >
T * DebugPoison (T *array, size_t elems)
 Fills memory with BIG_BAD_NUMBER, measured in elements.
template<typename T >
T * DebugPoisonBytes (T *array, size_t bytes)
 Fills memory with BIG_BAD_NUMBER, measured in bytes.
template<typename T >
T ** Destruct (T **array, size_t elems=1)
 No-op destructs an array of pointers.
template<typename T >
T * Destruct (T *array, size_t elems)
 Destructs each element in an array.
template<typename T >
T * Destruct (T *ptr)
 Destructs an element.
template<typename T >
void Free (T *ptr)
 Frees memory allocated by mem::Alloc and its derivatives.
template<typename T >
void FreeDestruct (T *array, size_t elems=1)
 Destructs and frees an array.
template<typename T >
T * Move (T *dest, const T *src, size_t elems=1)
template<typename V , typename T , typename U >
T * Move (T *dest, const U *src, size_t elems=1)
 Bit-moves elements from src to dest, permitting overlap.
template<typename T , typename U >
T * MoveBytes (T *dest, const U *src, size_t bytes)
 Bit-moves bytes from src to dest, permitting overlap.
template<typename T >
T * Poison (T *ptr)
 Fills an element with BIG_BAD_NUMBER.
template<typename T >
T * Poison (T *array, size_t elems)
 Fills memory with BIG_BAD_NUMBER, measured in elements.
template<typename T >
T * PoisonBytes (T *array, size_t bytes)
 Fills memory with BIG_BAD_NUMBER, measured in bytes.
template<typename T >
ptrdiff_t PtrAbsAddr (const T *ptr)
 Converts a pointer to its integral absolute address.
template<typename T >
const T * PtrAddBytes (const T *ptr, ptrdiff_t bytes)
 Offsets a const pointer by a given number of bytes.
template<typename T >
T * PtrAddBytes (T *ptr, ptrdiff_t bytes)
 Offsets a pointer by a given number of bytes.
template<typename T , typename U >
ptrdiff_t PtrDiffBytes (const T *lhs, const U *rhs)
 Finds the byte difference of two pointers, i.e.
template<typename T , typename U >
bool PtrsEqual (const T *lhs, const U *rhs)
 Determines if two pointers are the same, i.e.
template<typename T >
T * Realloc (T *array, size_t elems)
 Resizes allocated memory, measured in elements.
template<typename T >
T * ReallocBytes (T *array, size_t bytes)
 Resizes allocated memory, mesured in bytes.
template<typename T , typename U >
T * RepeatConstruct (T *array, const U &init, size_t elems)
 Constructs each element in an array with an initial value.
template<typename T >
void Swap (T *a, T *b)
template<typename V , typename T , typename U >
void Swap (T *a, U *b)
template<typename T >
void Swap (T *a, T *b, size_t elems)
template<typename V , typename T , typename U >
void Swap (T *a, U *b, size_t elems)
 Bit-swaps two arrays, measured in elements.
template<typename T , typename U >
void SwapBytes (T *a, U *b, size_t bytes)
 Bit-swaps two arrays, measured in bytes.
template<typename T >
T * Zero (T *array, size_t elems=1)
 Bit-zeros memory, measured in elements.
template<typename T >
T * ZeroBytes (T *array, size_t bytes)
 Bit-zeros memory, measured in bytes.

Detailed Description

Wrappers and tools for low-level memory management, including:

You likely do not need to care about these functions: use new and delete (like normal) for allocation of single objects and FASTlib's ArrayList (or Vector or Matrix) for arrays.

If you really need to manage your own memory, use these instead of malloc and free, because these will perform "memory poising" in debug mode.


Function Documentation

template<typename T >
T * mem::Alloc (  )  [inline]

Allocates a (debug) poisoned element.

Definition at line 146 of file ccmem.h.

References DebugPoisonBytes().

template<typename T >
T * mem::Alloc ( size_t  elems  )  [inline]

Allocates a (debug) poisoned array, measured in elements.

Definition at line 137 of file ccmem.h.

template<typename T >
T * mem::AllocBytes ( size_t  bytes  )  [inline]

Allocates a (debug) poisoned array, measured in bytes.

Definition at line 126 of file ccmem.h.

References DebugPoisonBytes().

Referenced by OrthoRangeSearch< T >::SaveTree().

template<typename T >
T * mem::AllocConstruct ( size_t  elems = 1  )  [inline]

Allocates and default constructs an array.

Definition at line 425 of file ccmem.h.

References Construct().

template<typename T , typename U >
T * mem::AllocCopy ( const U *  src,
size_t  elems = 1 
) [inline]

Allocates an array bit-copied from src, measured in elements.

Definition at line 207 of file ccmem.h.

Referenced by GenMatrix< double >::Copy(), and GenVector< index_t >::Copy().

template<typename T , typename U >
T * mem::AllocCopyBytes ( const U *  src,
size_t  bytes 
) [inline]

Allocates an array bit-copied from src, measured in bytes.

Definition at line 200 of file ccmem.h.

References CopyBytes().

template<typename T , typename U >
T * mem::AllocCopyConstruct ( const U *  src,
size_t  elems = 1 
) [inline]

Allocates and element-wise copy constructs an array.

Definition at line 430 of file ccmem.h.

References CopyConstruct().

template<typename T , typename U >
T * mem::AllocRepeatConstruct ( const U &  init,
size_t  elems 
) [inline]

Allocates and copy constructs an array.

Definition at line 439 of file ccmem.h.

References RepeatConstruct().

template<typename T >
T * mem::AllocZero ( size_t  elems = 1  )  [inline]

Allocates a bit-zerod array, measured in elements.

Definition at line 171 of file ccmem.h.

template<typename T >
T * mem::AllocZeroBytes ( size_t  bytes  )  [inline]

Allocates a bit-zerod array, measured in bytes.

Definition at line 164 of file ccmem.h.

template<typename T >
T * mem::BitCopy ( T *  dest,
const T *  src,
size_t  elems = 1 
) [inline]

Renamed Copy.

Definition at line 504 of file ccmem.h.

References Copy().

template<typename T , typename U >
T * mem::BitCopyBytes ( T *  dest,
const U *  src,
size_t  bytes 
) [inline]

Renamed CopyBytes.

Definition at line 499 of file ccmem.h.

References CopyBytes().

template<typename T >
void mem::BitSwap ( T *  a,
T *  b,
size_t  elems = 1 
) [inline]

Renamed Swap.

Definition at line 509 of file ccmem.h.

References Swap().

template<typename T >
T * mem::BitZero ( T *  array,
size_t  elems = 1 
) [inline]

Renamed Zero.

Definition at line 494 of file ccmem.h.

References Zero().

template<typename T >
T * mem::BitZeroBytes ( T *  array,
size_t  bytes 
) [inline]

Renamed ZeroBytes.

Definition at line 489 of file ccmem.h.

References ZeroBytes().

template<typename T >
T ** mem::Construct ( T **  array,
size_t  elems = 1 
) [inline]

No-op constructs an array of pointers.

Definition at line 398 of file ccmem.h.

References DebugPoison().

template<typename T >
T * mem::Construct ( T *  array,
size_t  elems 
) [inline]

Default constructs each element in an array.

Definition at line 333 of file ccmem.h.

template<typename T >
T * mem::Construct ( T *  ptr  )  [inline]

Default Constructs An element.

Definition at line 327 of file ccmem.h.

Referenced by AllocConstruct().

template<typename V , typename T , typename U >
T * mem::Copy ( T *  dest,
const U *  src,
size_t  elems = 1 
) [inline]
template<typename T , typename U >
T * mem::CopyBytes ( T *  dest,
const U *  src,
size_t  bytes 
) [inline]

Bit-copies from src to dest, measured in bytes.

Definition at line 179 of file ccmem.h.

Referenced by AllocCopyBytes(), BitCopyBytes(), and Copy().

template<typename T >
T ** mem::CopyConstruct ( T **  dest,
const T **  src,
size_t  elems = 1 
) [inline]

Bit-copy copy constructs an array of pointers.

Definition at line 408 of file ccmem.h.

References Copy().

template<typename T , typename U >
T * mem::CopyConstruct ( T *  dest,
const U *  src,
size_t  elems 
) [inline]

Element-wise copy constructs one array given another.

Definition at line 359 of file ccmem.h.

template<typename T , typename U >
T * mem::CopyConstruct ( T *  dest,
const U *  src 
) [inline]

Element-wise copy constructs one element given another.

Definition at line 353 of file ccmem.h.

Referenced by AllocCopyConstruct().

template<typename T >
T * mem::DebugPoison ( T *  ptr  )  [inline]

Fills an element with BIG_BAD_NUMBER.

Definition at line 119 of file ccmem.h.

References Poison().

template<typename T >
T * mem::DebugPoison ( T *  array,
size_t  elems 
) [inline]

Fills memory with BIG_BAD_NUMBER, measured in elements.

Definition at line 113 of file ccmem.h.

References Poison().

Referenced by ot::Construct(), Construct(), GenMatrix< double >::Destruct(), GenVector< index_t >::Destruct(), ot::Destruct(), and Destruct().

template<typename T >
T * mem::DebugPoisonBytes ( T *  array,
size_t  bytes 
) [inline]

Fills memory with BIG_BAD_NUMBER, measured in bytes.

Definition at line 107 of file ccmem.h.

References PoisonBytes().

Referenced by Alloc(), and AllocBytes().

template<typename T >
T ** mem::Destruct ( T **  array,
size_t  elems = 1 
) [inline]

No-op destructs an array of pointers.

Definition at line 403 of file ccmem.h.

References DebugPoison().

template<typename T >
T * mem::Destruct ( T *  array,
size_t  elems 
) [inline]

Destructs each element in an array.

Definition at line 345 of file ccmem.h.

References DebugPoison().

template<typename T >
T * mem::Destruct ( T *  ptr  )  [inline]

Destructs an element.

Definition at line 339 of file ccmem.h.

References DebugPoison().

Referenced by FreeDestruct().

template<typename T >
void mem::Free ( T *  ptr  )  [inline]
template<typename T >
void mem::FreeDestruct ( T *  array,
size_t  elems = 1 
) [inline]

Destructs and frees an array.

Definition at line 449 of file ccmem.h.

References Destruct(), and Free().

template<typename V , typename T , typename U >
T * mem::Move ( T *  dest,
const U *  src,
size_t  elems = 1 
) [inline]

Bit-moves elements from src to dest, permitting overlap.

Definition at line 315 of file ccmem.h.

References MoveBytes().

Referenced by ArrayList< std::pair< index_t, index_t > >::InsertRaw(), and ArrayList< std::pair< index_t, index_t > >::RemoveRaw().

template<typename T , typename U >
T * mem::MoveBytes ( T *  dest,
const U *  src,
size_t  bytes 
) [inline]

Bit-moves bytes from src to dest, permitting overlap.

Definition at line 310 of file ccmem.h.

Referenced by Move().

template<typename T >
T * mem::Poison ( T *  ptr  )  [inline]

Fills an element with BIG_BAD_NUMBER.

Definition at line 96 of file ccmem.h.

References PoisonBytes().

template<typename T >
T * mem::Poison ( T *  array,
size_t  elems 
) [inline]

Fills memory with BIG_BAD_NUMBER, measured in elements.

Definition at line 91 of file ccmem.h.

References PoisonBytes().

Referenced by DebugPoison().

template<typename T >
T * mem::PoisonBytes ( T *  array,
size_t  bytes 
) [inline]

Fills memory with BIG_BAD_NUMBER, measured in bytes.

Definition at line 84 of file ccmem.h.

Referenced by DebugPoisonBytes(), and Poison().

template<typename T >
ptrdiff_t mem::PtrAbsAddr ( const T *  ptr  )  [inline]

Converts a pointer to its integral absolute address.

Definition at line 475 of file ccmem.h.

template<typename T >
const T * mem::PtrAddBytes ( const T *  ptr,
ptrdiff_t  bytes 
) [inline]

Offsets a const pointer by a given number of bytes.

Definition at line 463 of file ccmem.h.

template<typename T >
T * mem::PtrAddBytes ( T *  ptr,
ptrdiff_t  bytes 
) [inline]

Offsets a pointer by a given number of bytes.

Definition at line 457 of file ccmem.h.

template<typename T , typename U >
ptrdiff_t mem::PtrDiffBytes ( const T *  lhs,
const U *  rhs 
) [inline]

Finds the byte difference of two pointers, i.e.

lhs - rhs.

Definition at line 469 of file ccmem.h.

template<typename T , typename U >
bool mem::PtrsEqual ( const T *  lhs,
const U *  rhs 
) [inline]

Determines if two pointers are the same, i.e.

lhs == rhs.

Definition at line 480 of file ccmem.h.

template<typename T >
T * mem::Realloc ( T *  array,
size_t  elems 
) [inline]

Resizes allocated memory, measured in elements.

Added elements (if any) are not poisoned or zeroed. The input pointer is invalidated and should be replaced by the return in all subsequent uses.

Definition at line 245 of file ccmem.h.

Referenced by String::InitSprintf(), DenseIntMap< TValue >::operator[](), ArrayList< std::pair< index_t, index_t > >::Reserve(), GenMatrix< double >::ResizeNoalias(), and ArrayList< std::pair< index_t, index_t > >::Trim().

template<typename T >
T * mem::ReallocBytes ( T *  array,
size_t  bytes 
) [inline]

Resizes allocated memory, mesured in bytes.

Added bytes (if any) are not poisoned or zeroed. The input pointer is invalidated and should be replaced by the return in all subsequent uses.

Definition at line 232 of file ccmem.h.

template<typename T , typename U >
T * mem::RepeatConstruct ( T *  array,
const U &  init,
size_t  elems 
) [inline]

Constructs each element in an array with an initial value.

Definition at line 416 of file ccmem.h.

Referenced by AllocRepeatConstruct(), GenMatrix< double >::SetAll(), and GenVector< index_t >::SetAll().

template<typename V , typename T , typename U >
void mem::Swap ( T *  a,
U *  b,
size_t  elems 
) [inline]

Bit-swaps two arrays, measured in elements.

This code is optimized for swapping arrays starting at multiple-of-eight byte locations. Freshly allocated memory and all locations within arrays of longs, doubles, and most structs will have this property. Suboptimal performance will arise only when swapping between offset locations in arrays of small types, such as portions of strings.

Definition at line 284 of file ccmem.h.

References SwapBytes().

Referenced by BitSwap(), GenMatrix< double >::SwapValues(), and GenVector< index_t >::SwapValues().

template<typename T , typename U >
void mem::SwapBytes ( T *  a,
U *  b,
size_t  bytes 
) [inline]

Bit-swaps two arrays, measured in bytes.

This code works best for arrays starting at multiple-of-eight (and higher powers of two) byte locations. Freshly allocated memory and locations within arrays of longs, doubles, and most structs will have this property. Suboptimal performance arises when swapping between offset locations in arrays of small types, such as portions of strings.

Definition at line 268 of file ccmem.h.

Referenced by Swap().

template<typename T >
T * mem::Zero ( T *  array,
size_t  elems = 1 
) [inline]

Bit-zeros memory, measured in elements.

Definition at line 159 of file ccmem.h.

References ZeroBytes().

Referenced by BitZero().

template<typename T >
T * mem::ZeroBytes ( T *  array,
size_t  bytes 
) [inline]

Bit-zeros memory, measured in bytes.

Definition at line 154 of file ccmem.h.

Referenced by BitZeroBytes(), and Zero().

Generated on Mon Jan 24 12:04:41 2011 for FASTlib by  doxygen 1.6.3