/************************************************************************** File: malloc4.c 2,3,4 dimensional memory allocators. written by Xavier Bouyssounouse ***************************************************************************/ #include #include #include "malloc4.h" #define STOP_FLAG 1 #ifdef ANSI_FUNC unsigned char *malloc1( unsigned int size ) #else unsigned char *malloc1(size) unsigned int size; #endif { char *ptr; if ((int)(ptr= malloc(size))% sizeof(double)) fprintf(stderr,"Warning: malloc returned pointer on invalid boundary.\n"); return (unsigned char *) ptr; } #ifdef ANSI_FUNC void free2( unsigned char **temp2 ) #else void free2(temp2) unsigned char **temp2; #endif /*****************************************************/ /* Frees 2D memory allocated by malloc2 or malloc2c. */ /*****************************************************/ { int i=0; while (temp2[i]) free((char *) temp2[i++]); free((char *) temp2); } #ifdef ANSI_FUNC unsigned char **malloc2( int n2, int n1 ) #else unsigned char **malloc2(n2,n1) int n2,n1; #endif /********************************/ /* Dynamic 2D memory allocator. */ /********************************/ { unsigned char **temp2; int i; if (!(temp2 = (unsigned char **) malloc1((n2+1)*sizeof(*temp2)+sizeof(int)))) return NULL; temp2[n2] = NULL; for (i=0; i