Functions

cmtk::Memory Namespace Reference
[cmtkSystem Library]

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 >
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.

Detailed Description

Memory-related helper functions.


Function Documentation

template<class T >
T* cmtk::Memory::AllocateArray ( const size_t  size ) [inline]

Memory allocation for array.

Warning:
If this function allocates memory with anything other than the C++ new[] operator, then objects in the array will not be instantiated.

Definition at line 63 of file cmtkMemory.h.

template<class T >
T cmtk::Memory::ByteSwap ( value )
template<class T >
void cmtk::Memory::ByteSwapInPlace ( T &  value )

Byte-swap arbitrary value in place.

Definition at line 116 of file cmtkMemory.h.

template<class T >
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.

template<class T >
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.

Parameters:
beforeNumber of bytes allocated before the inspected operation. This parameter can be retrieved by al call to memused().
msgName 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 )
void cmtk::Memory::Info ( const char *  msg = NULL )

Print memory usage.

Parameters:
msgAn 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().

template<class T >
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.

Returns:
The number of bytes allocated by the process the calling function is located in.

Definition at line 67 of file cmtkMemory.cxx.

Referenced by Diff(), and Info().

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines