Memory-related helper functions. More...
Functions | |
size_t | GetNextPowerOfTwo (size_t k) |
Utility function: get next power of two. | |
template<class T > | |
T * | AllocateArray (const size_t size) |
Memory allocation for array. | |
template<class T > | |
void | DeleteArray (T *const array) |
Delete an array allocated using AllocateArray(). | |
template<class T > | |
void | Set (T *const to, const T value, const size_t length) |
Set (fill) memory region with given value. | |
template<class T > | |
void | Copy (T *const to, const T *from, const size_t length) |
Copy memory region. | |
template<class T > | |
T | ByteSwap (T value) |
Byte-swap arbitrary value. | |
template<class T > | |
void | ByteSwapInPlace (T &value) |
Byte-swap arbitrary value in place. | |
Functions for tracing memory allocation and de-allocation. | |
These functions can be used to watch the amount of memory allocated and freed by other functions. Memory holes can be identified and located. | |
size_t | Used () |
Get amount of memory used. | |
void | Info (const char *msg=NULL) |
Print memory usage. | |
void | Diff (const size_t before, const char *msg) |
Print difference of memory usage. |
Memory-related helper functions.
T* cmtk::Memory::AllocateArray | ( | const size_t | size ) | [inline] |
Memory allocation for array.
Definition at line 63 of file cmtkMemory.h.
T cmtk::Memory::ByteSwap | ( | T | value ) |
Byte-swap arbitrary value.
Definition at line 101 of file cmtkMemory.h.
Referenced by cmtk::FileHeader::GetArray(), cmtk::FileHeader::GetField(), cmtk::VolumeFromFile::ReadBioRad(), and cmtk::FileHeader::StoreField().
void cmtk::Memory::ByteSwapInPlace | ( | T & | value ) |
Byte-swap arbitrary value in place.
Definition at line 116 of file cmtkMemory.h.
void cmtk::Memory::Copy | ( | T *const | to, |
const T * | from, | ||
const size_t | length | ||
) | [inline] |
Copy memory region.
This is the templated version of memcpy()
Definition at line 93 of file cmtkMemory.h.
void cmtk::Memory::DeleteArray | ( | T *const | array ) | [inline] |
Delete an array allocated using AllocateArray().
Definition at line 72 of file cmtkMemory.h.
Referenced by cmtk::ActiveDeformationModel< W >::ActiveDeformationModel(), cmtk::Vector< Types::Coordinate >::AdjustDimension(), cmtk::TemplateArray< T >::Alloc(), cmtk::GroupwiseRegistrationFunctionalBase::AllocateStorage(), cmtk::SearchTrace< R >::Clear(), cmtk::CongealingFunctional< TXform >::CreateGaussianKernels(), cmtk::DeviceUniformVolumeArray::DeviceUniformVolumeArray(), cmtk::VolumeFromSlices::FinishVolume(), cmtk::TemplateArray< T >::FreeData(), cmtk::ClassStream::Get(), cmtk::TypedArraySimilarity::GetCorrelationRatio(), cmtk::DataGridFilter::GetDataMedianFiltered(), cmtk::ImageRGB::GetDataPtr(), cmtk::ScalarImage::GetMedianFiltered(), cmtk::Vector< Types::Coordinate >::operator=(), cmtk::ScalarImageIO::ReadAnalyze(), cmtk::VolumeFromFile::ReadAnalyzeHdr(), cmtk::VolumeFromFile::ReadNifti(), cmtk::UniformVolume::Resample(), cmtk::Matrix3D< T >::Resize(), cmtk::Matrix2D< T * >::Resize(), cmtk::ImageRGB::SetAlphaChannel(), cmtk::Vector< Types::Coordinate >::SetDim(), cmtk::VoxelMatchingElasticFunctional_WarpTemplate< W >::SetWarpXform(), cmtk::PGM::Write(), cmtk::PGM::Write16bit(), cmtk::ScalarImageIO::WriteAnalyze(), cmtk::VolumeFromFile::WriteAnalyzeHdr(), cmtk::GroupwiseRegistrationOutput::WriteAverageImage(), cmtk::BitVector::~BitVector(), cmtk::CongealingFunctional< TXform >::~CongealingFunctional(), cmtk::EntropyMinimizationIntensityCorrectionFunctional< NOrderAdd, NOrderMul >::~EntropyMinimizationIntensityCorrectionFunctional(), cmtk::GroupwiseRegistrationFunctionalBase::~GroupwiseRegistrationFunctionalBase(), cmtk::ImagePairNonrigidRegistrationFunctional::~ImagePairNonrigidRegistrationFunctional(), cmtk::ImageRGB::~ImageRGB(), cmtk::Matrix2D< T * >::~Matrix2D(), cmtk::ParallelElasticFunctional< VM >::~ParallelElasticFunctional(), cmtk::ThreadParameterArray< TClass, TParam >::~ThreadParameterArray(), cmtk::TransformedVolumeAxes::~TransformedVolumeAxes(), cmtk::Vector< Types::Coordinate >::~Vector(), cmtk::VoxelMatchingElasticFunctional::~VoxelMatchingElasticFunctional(), and cmtk::VoxelMatchingElasticFunctional_Template< VM >::~VoxelMatchingElasticFunctional_Template().
void cmtk::Memory::Diff | ( | const size_t | before, |
const char * | msg | ||
) |
Print difference of memory usage.
before | Number of bytes allocated before the inspected operation. This parameter can be retrieved by al call to memused(). |
msg | Name of the operation the memory allocation of which was inspected. |
Definition at line 88 of file cmtkMemory.cxx.
References Used().
size_t cmtk::Memory::GetNextPowerOfTwo | ( | size_t | k ) |
Utility function: get next power of two.
http://en.wikipedia.org/wiki/Power_of_two#Algorithm_to_find_the_next-highest_power_of_two
Definition at line 51 of file cmtkMemory.cxx.
Referenced by cmtk::DeviceHistogram::DeviceHistogram().
void cmtk::Memory::Info | ( | const char * | msg = NULL ) |
Print memory usage.
msg | An optional message to be printed with the amount of bytes allocated by the current process. This allows location of memory holes. The parameter may be omitted or given as NULL if no additional message is required. |
Definition at line 78 of file cmtkMemory.cxx.
References Used().
void cmtk::Memory::Set | ( | T *const | to, |
const T | value, | ||
const size_t | length | ||
) | [inline] |
Set (fill) memory region with given value.
This is the templated version of memset()
Definition at line 82 of file cmtkMemory.h.
Referenced by cmtk::BitVector::BitVector(), cmtk::Matrix3x3< Types::Coordinate >::Matrix3x3(), and cmtk::Matrix4x4< Types::Coordinate >::Matrix4x4().
size_t cmtk::Memory::Used | ( | ) |
Get amount of memory used.
Definition at line 67 of file cmtkMemory.cxx.