diff --git a/include/matrix_alloc.hpp b/include/matrix_alloc.hpp index 80459ba..690f504 100644 --- a/include/matrix_alloc.hpp +++ b/include/matrix_alloc.hpp @@ -11,39 +11,38 @@ namespace matrix_alloc { -/// @brief Allocate a 2-dimensional table row-major order. +/// @brief Allocate a 2-dimensional array. (Uses row-major order.) template void Alloc2D(size_t nrows, //!< size of the array (number of rows) size_t ncols, //!< size of the array (number of columns) - Entry ***paaX //!< pointer to a 2-D C-style array + Entry ***paaX //!< pointer to a 2D C-style array ); -/// @brief This function is the corresponding way to deallocate -/// arrays that were created using Alloc2D(). +/// @brief Deallocate arrays that were created using Alloc2D(). template -void Dealloc2D(Entry ***paaX //!< pointer to 2-D multidimensional array +void Dealloc2D(Entry ***paaX //!< pointer to a 2D C-style array ); -// --- IMPLEMENTATION --- + +// ---- IMPLEMENTATION ---- + template void Alloc2D(size_t nrows, // size of the array (number of rows) size_t ncols, // size of the array (number of columns) - Entry ***paaX) // pointer to a 2-D C-style array + Entry ***paaX) // pointer to a 2D C-style array { assert(paaX); - // Allocate a conventional 2-dimensional - // pointer-to-a-pointer data structure. - *paaX = new Entry* [nrows]; - (*paaX)[0] = new Entry [nrows * ncols]; + *paaX = new Entry* [nrows]; //conventional 2D C array (pointer-to-pointer) + (*paaX)[0] = new Entry [nrows * ncols]; // 1D C array (contiguous memor) for(size_t iy=0; iy -void Dealloc2D(Entry ***paaX) // pointer to 2-D multidimensional array +void Dealloc2D(Entry ***paaX) // pointer to a 2D C-style array { if (paaX && *paaX) { delete [] (*paaX)[0];