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. |
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.
T * mem::Alloc | ( | ) | [inline] |
Allocates a (debug) poisoned element.
Definition at line 146 of file ccmem.h.
References DebugPoisonBytes().
T * mem::Alloc | ( | size_t | elems | ) | [inline] |
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().
T * mem::AllocConstruct | ( | size_t | elems = 1 |
) | [inline] |
Allocates and default constructs an array.
Definition at line 425 of file ccmem.h.
References Construct().
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().
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().
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().
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().
T * mem::AllocZero | ( | size_t | elems = 1 |
) | [inline] |
T * mem::AllocZeroBytes | ( | size_t | bytes | ) | [inline] |
T * mem::BitCopy | ( | T * | dest, | |
const T * | src, | |||
size_t | elems = 1 | |||
) | [inline] |
T * mem::BitCopyBytes | ( | T * | dest, | |
const U * | src, | |||
size_t | bytes | |||
) | [inline] |
void mem::BitSwap | ( | T * | a, | |
T * | b, | |||
size_t | elems = 1 | |||
) | [inline] |
T * mem::BitZero | ( | T * | array, | |
size_t | elems = 1 | |||
) | [inline] |
T * mem::BitZeroBytes | ( | T * | array, | |
size_t | bytes | |||
) | [inline] |
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().
T * mem::Construct | ( | T * | array, | |
size_t | elems | |||
) | [inline] |
T * mem::Construct | ( | T * | ptr | ) | [inline] |
Default Constructs An element.
Definition at line 327 of file ccmem.h.
Referenced by AllocConstruct().
T * mem::Copy | ( | T * | dest, | |
const U * | src, | |||
size_t | elems = 1 | |||
) | [inline] |
Bit-copies from src to dest, measured in elements.
Definition at line 184 of file ccmem.h.
References CopyBytes().
Referenced by ArrayList< TElem >::AppendSteal(), BitCopy(), CopyConstruct(), ArrayList< std::pair< index_t, index_t > >::ExtractInit(), ArrayList< TElem >::InfixSteal(), ArrayList< std::pair< index_t, index_t > >::PopBackInit(), ArrayList< std::pair< index_t, index_t > >::RemoveInit(), ArrayList< std::pair< index_t, index_t > >::SegmentInit(), and Dataset::SplitTrainTest().
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().
T ** mem::CopyConstruct | ( | T ** | dest, | |
const T ** | src, | |||
size_t | elems = 1 | |||
) | [inline] |
T * mem::CopyConstruct | ( | T * | dest, | |
const U * | src, | |||
size_t | elems | |||
) | [inline] |
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().
T * mem::DebugPoison | ( | T * | ptr | ) | [inline] |
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().
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().
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().
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().
T * mem::Destruct | ( | T * | ptr | ) | [inline] |
Destructs an element.
Definition at line 339 of file ccmem.h.
References DebugPoison().
Referenced by FreeDestruct().
void mem::Free | ( | T * | ptr | ) | [inline] |
Frees memory allocated by mem::Alloc and its derivatives.
Definition at line 251 of file ccmem.h.
Referenced by ArrayList< TElem >::AppendSteal(), ArrayList< std::pair< index_t, index_t > >::Clear(), GenMatrix< double >::Destruct(), GenVector< index_t >::Destruct(), FreeDestruct(), ArrayList< TElem >::InfixSteal(), OrthoRangeSearch< T >::SaveTree(), and OrthoRangeSearch< T >::~OrthoRangeSearch().
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().
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().
T * mem::MoveBytes | ( | T * | dest, | |
const U * | src, | |||
size_t | bytes | |||
) | [inline] |
T * mem::Poison | ( | T * | ptr | ) | [inline] |
Fills an element with BIG_BAD_NUMBER.
Definition at line 96 of file ccmem.h.
References PoisonBytes().
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().
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().
ptrdiff_t mem::PtrAbsAddr | ( | const T * | ptr | ) | [inline] |
const T * mem::PtrAddBytes | ( | const T * | ptr, | |
ptrdiff_t | bytes | |||
) | [inline] |
T * mem::PtrAddBytes | ( | T * | ptr, | |
ptrdiff_t | bytes | |||
) | [inline] |
ptrdiff_t mem::PtrDiffBytes | ( | const T * | lhs, | |
const U * | rhs | |||
) | [inline] |
bool mem::PtrsEqual | ( | const T * | lhs, | |
const U * | rhs | |||
) | [inline] |
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().
T * mem::ReallocBytes | ( | T * | array, | |
size_t | bytes | |||
) | [inline] |
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().
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().
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().
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().
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().