#include /*! \file \brief Functions for dynamical array allocation. $Id: amalloc.C,v 1.11 2012/03/26 13:50:11 chulwoo Exp $ */ #include #include #include #include #include CPS_START_NAMESPACE // ------------------------------------------------------------ /*! This is a utility routine for amalloc(). \param size Size (in bytes) of objects in the array. \param n_dim Dimension of this subarray. \param n_ptr Number of pointers we need to set. \param prev Location of the pointers. \param start Location of this subarray. \param dimension The array dimensions. \param index Recursion depth - the array index of this subarray */ // ------------------------------------------------------------ static const size_t alignment = 128; static void subarray(size_t size, int n_dim, int n_ptr, void ***prev, void **start, int *dimension, int index){ int i, dim = dimension[index]; if(n_dim>0){ // Set up pointers to pointers for(i=0; iviz. ::smalloc or ::fmalloc. \param size The size (in bytes) of the elements of the array. \param n_dim The dimensionality of the array. \param ... The dimensions of the array. \return A pointer to the allocated memory */ void *amalloc(void* (*allocator)(size_t, const char *vname, const char *fname, const char *cname), size_t size, int n_dim, ...){ /* The first bit of data in the array are pointers which point to the data in the next dimension, which are pointers to data in the next dimension, and so on, until the penultimate dimension, where the pointers point to the actual data. */ ERR.NotImplemented("","amalloc"); int *dimension = (int*)smalloc(n_dim*sizeof(int)); // Count the pointers and data elements in the array. va_list ap; va_start(ap, n_dim); int d, n_ptr = 0, n_data = 1; for(d = 0; d