#include <stdio.h>
#include <string.h>
#include <stdlib.h>
Go to the source code of this file.
char* BuildIndirectionTable |
( |
| ) |
|
char* BuildIndirectionTable |
( |
unsigned |
nDim, |
|
|
Dims |
, |
|
|
char *** |
nextFreeTable, |
|
|
char ** |
nextFreeArray, |
|
|
unsigned |
sizeofelt |
|
) |
| |
Definition at line 184 of file mallocNd.c.
192 char *ReturnValue, **table;
195 ReturnValue = *nextFreeArray;
196 *nextFreeArray += sizeofelt * Dims[0];
201 table = *nextFreeTable;
202 *nextFreeTable += Dims[0];
203 for(i=0; i<Dims[0]; i++)
206 nextFreeArray, sizeofelt );
208 ReturnValue = (
char *) table;
char * BuildIndirectionTable()
char* malloc_2d |
( |
int |
n, |
|
|
int |
m, |
|
|
int |
sizeofelt |
|
) |
| |
Definition at line 218 of file mallocNd.c.
char * mallocNd(unsigned int nDim, Dims, unsigned int sizeofelt)
char* mallocNd |
( |
unsigned int |
nDim, |
|
|
Dims |
, |
|
|
unsigned int |
sizeofelt |
|
) |
| |
Definition at line 125 of file mallocNd.c.
131 char *
ptr, *tableBase, *arrayBase, *nextFreeArray, *nextFreeTable;
132 unsigned int arrayBytesNeeded, tableBytesNeeded, dimProduct, slop;
137 tableBytesNeeded = 0;
139 for(i=0; i<nDim-1; i++)
141 dimProduct *= Dims[
i];
142 tableBytesNeeded += dimProduct*
sizeof(
char *);
146 slop = (tableBytesNeeded % sizeofelt);
148 slop = sizeofelt - slop;
151 dimProduct *= Dims[
i];
152 arrayBytesNeeded = dimProduct*sizeofelt;
155 ptr =
malloc( tableBytesNeeded + slop + arrayBytesNeeded );
156 if (ptr == NULL)
return (
char *) NULL;
160 arrayBase = ptr + slop + tableBytesNeeded;
163 nextFreeTable = tableBase;
164 nextFreeArray = arrayBase;
168 &nextFreeArray, sizeofelt );
173 if (nextFreeTable != arrayBase - slop ||
174 nextFreeArray != ptr + tableBytesNeeded + slop + arrayBytesNeeded)
176 fprintf( stderr,
"Error in mallocNd! Memory overwrite." );
179 return(
char *) tableBase;
char * BuildIndirectionTable()