00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef GV_MEMORY_H
00018 #define GV_MEMORY_H
00019
00020 #include <stdlib.h>
00021 #ifdef HAVE_MALLOC_H
00022 #include <malloc.h>
00023 #endif
00024
00025 #ifdef __cplusplus
00026 extern "C" {
00027 #endif
00028
00029 #ifdef DMALLOC
00030 #define NEW(t) (t*)calloc(1,sizeof(t))
00031 #define N_NEW(n,t) (t*)calloc((n),sizeof(t))
00032 #define GNEW(t) (t*)malloc(sizeof(t))
00033 #define N_GNEW(n,t) (t*)malloc((n)*sizeof(t))
00034 #define ALLOC(size,ptr,type) (ptr? (type*)realloc(ptr,(size)*sizeof(type)):(type*)malloc((size)*sizeof(type)))
00035 #define RALLOC(size,ptr,type) ((type*)realloc(ptr,(size)*sizeof(type)))
00036 #define ZALLOC(size,ptr,type,osize) (ptr? (type*)recalloc(ptr,(size)*sizeof(type)):(type*)calloc((size),sizeof(type)))
00037 #else
00038 #define NEW(t) (t*)zmalloc(sizeof(t))
00039 #define N_NEW(n,t) (t*)zmalloc((n)*sizeof(t))
00040 #define GNEW(t) (t*)gmalloc(sizeof(t))
00041 #define N_GNEW(n,t) (t*)gmalloc((n)*sizeof(t))
00042 #define ALLOC(size,ptr,type) (ptr? (type*)grealloc(ptr,(size)*sizeof(type)):(type*)gmalloc((size)*sizeof(type)))
00043 #define RALLOC(size,ptr,type) ((type*)grealloc(ptr,(size)*sizeof(type)))
00044 #define ZALLOC(size,ptr,type,osize) (ptr? (type*)zrealloc(ptr,size,sizeof(type),osize):(type*)zmalloc((size)*sizeof(type)))
00045 #endif
00046
00047
00048 extern void *zmalloc(size_t);
00049 extern void *zrealloc(void *, size_t, size_t, size_t);
00050 extern void *gmalloc(size_t);
00051 extern void *grealloc(void *, size_t);
00052
00053 #ifdef __cplusplus
00054 }
00055 #endif
00056
00057 #endif