- Timestamp:
- May 31, 2011, 3:50:46 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20110505/Ohana/src/libohana/include/ohana_allocate.h
r31589 r31591 1 1 # ifndef OHANA_ALLOCATE 2 2 # define OHANA_ALLOCATE 3 4 typedef struct { 5 int exists; // has the memory management system been created? 6 size_t Ntotal; // number of blocks currently allocated 7 size_t Nbytes; // number of bytes currently allocated 8 size_t Ngood; // number of good blocks 9 size_t Nbad; // number of bad blocks 10 } OhanaMemstats; 11 12 OhanaMemstats ohana_memstats (int mode); 3 13 4 14 /* default is to use basic system memory functions */ 5 15 # ifdef OHANA_MEMORY 6 16 7 void *ohana_malloc (c har *file, int line,char *func, int Nelem, size_t esize);8 void *ohana_realloc (c har *file, int line,char *func, void *in, int Nelem, size_t esize);9 void ohana_free (c har *file, int line,char *func, void *in);17 void *ohana_malloc (const char *file, int line, const char *func, int Nelem, size_t esize); 18 void *ohana_realloc (const char *file, int line, const char *func, void *in, int Nelem, size_t esize); 19 void ohana_free (const char *file, int line, const char *func, void *in); 10 20 void ohana_memdump_func (int mode); 11 21 void ohana_memcheck_func (int mode); 22 void real_free (void *in); 12 23 13 24 # define ohana_memcheck(X) ohana_memcheck_func (X); 14 25 # define ohana_memdump(X) ohana_memdump_func (X); 15 26 16 # define ALLOCATE(PTR,TYPE,SIZE) \ 17 { PTR = (TYPE *) ohana_malloc (__FILE__, __LINE__, __func__, (SIZE), sizeof(TYPE)) } 18 # define ALLOCATE_ZERO(PTR,TYPE,SIZE) \ 19 { PTR = (TYPE *) ohana_malloc (__FILE__, __LINE__, __func__, (SIZE), sizeof(TYPE)); memset (PTR, 0, (SIZE)*sizeof(TYPE)); } 20 # define REALLOCATE(PTR,TYPE,SIZE) \ 21 { PTR = (TYPE *) ohana_realloc(__FILE__, __LINE__, __func__, PTR, (SIZE), sizeof(TYPE)); } 22 # define CHECK_REALLOCATE(PTR,TYPE,SIZE,NCURR,DELTA) { \ 23 if ((NCURR) >= (SIZE)) { SIZE += DELTA; \ 24 PTR = (TYPE *) ohana_realloc(__FILE__, __LINE__, __func__, PTR, (SIZE), sizeof(TYPE)); } } 27 # define ALLOCATE(PTR,TYPE,SIZE) { \ 28 PTR = (TYPE *) ohana_malloc (__FILE__, __LINE__, __func__, (SIZE), sizeof(TYPE)); \ 29 } 30 31 # define ALLOCATE_ZERO(PTR,TYPE,SIZE) { \ 32 PTR = (TYPE *) ohana_malloc (__FILE__, __LINE__, __func__, (SIZE), sizeof(TYPE)); \ 33 memset (PTR, 0, (SIZE)*sizeof(TYPE)); \ 34 } 35 36 # define REALLOCATE(PTR,TYPE,SIZE) { \ 37 PTR = (TYPE *) ohana_realloc(__FILE__, __LINE__, __func__, PTR, (SIZE), sizeof(TYPE)); \ 38 } 39 40 # define CHECK_REALLOCATE(PTR,TYPE,SIZE,NCURR,DELTA) { \ 41 if ((NCURR) >= (SIZE)) { \ 42 SIZE += DELTA; \ 43 PTR = (TYPE *) ohana_realloc(__FILE__, __LINE__, __func__, PTR, (SIZE), sizeof(TYPE)); \ 44 } } 45 25 46 # define FREE(PTR) { if (PTR != NULL) { ohana_free (__FILE__, __LINE__, __func__, PTR); } } 26 # define free(PTR) { ohana_free(__FILE__, __LINE__, PTR); } 27 # define real_free(PTR) { if (PTR) { free(PTR); }} 47 # define free(PTR) { ohana_free(__FILE__, __LINE__, __func__, PTR); } 28 48 29 # else /* OHANA_MEMORY */49 # else /* below: not OHANA_MEMORY */ 30 50 31 51 # define ohana_memcheck(X) /* NOP */ 32 52 # define ohana_memdump(X) /* NOP */ 33 # define real_free(PTR) { if (PTR) { free(PTR); }} 53 void real_free (void *in); 34 54 35 # ifndef ALLOCATE36 55 # define ALLOCATE(PTR,TYPE,SIZE) { \ 37 56 PTR = (TYPE *) malloc ((size_t)(MAX(((SIZE)*((int)sizeof(TYPE))),1))); \ … … 62 81 63 82 # define FREE(PTR) { if (PTR != NULL) { free (PTR); } } 64 # endif /* ALLOCATE */65 83 # endif /* OHANA_MEMORY */ 66 84
Note:
See TracChangeset
for help on using the changeset viewer.
