Changeset 31663 for trunk/Ohana/src/libohana/include/ohana_allocate.h
- Timestamp:
- Jun 22, 2011, 12:33:45 AM (15 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/libohana/include/ohana_allocate.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/libohana/include/ohana_allocate.h
r30726 r31663 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 (char *file, int line, int Nelem, size_t esize); 8 void *ohana_realloc (char *file, int line, void *in, int Nelem, size_t esize); 9 void ohana_free (char *file, int line, void *in); 10 void ohana_memregister_func (char *file, int line, void *ptr); 17 void *ohana_malloc (const char *file, int line, const char *func, size_t Nelem, size_t esize); 18 void *ohana_realloc (const char *file, int line, const char *func, void *in, size_t Nelem, size_t esize); 19 void ohana_free (const char *file, int line, const char *func, void *in); 11 20 void ohana_memdump_func (int mode); 12 21 void ohana_memcheck_func (int mode); 22 void real_free (void *in); 13 23 14 # define ohana_memregister(X) ohana_memregister_func (__FILE__, __LINE__, (X));15 24 # define ohana_memcheck(X) ohana_memcheck_func (X); 16 25 # define ohana_memdump(X) ohana_memdump_func (X); 17 26 18 # define ALLOCATE(PTR,TYPE,SIZE) \ 19 { PTR = (TYPE *) ohana_malloc (__FILE__, __LINE__, (SIZE), sizeof(TYPE)) } 20 # define ALLOCATE_ZERO(PTR,TYPE,SIZE) \ 21 { PTR = (TYPE *) ohana_malloc (__FILE__, __LINE__, (SIZE), sizeof(TYPE)); memset (PTR, 0, (SIZE)*sizeof(TYPE)); } 22 # define REALLOCATE(PTR,TYPE,SIZE) \ 23 { PTR = (TYPE *) ohana_realloc(__FILE__, __LINE__, PTR, (SIZE), sizeof(TYPE)); } 24 # define CHECK_REALLOCATE(PTR,TYPE,SIZE,NCURR,DELTA) { \ 25 if ((NCURR) >= (SIZE)) { SIZE += DELTA; \ 26 PTR = (TYPE *) ohana_realloc(__FILE__, __LINE__, PTR, (SIZE), sizeof(TYPE)); } } 27 # define FREE(PTR) { if (PTR != NULL) { ohana_free (__FILE__, __LINE__, PTR); } } 28 # define free(PTR) { ohana_free(__FILE__, __LINE__, PTR); } 27 # define ALLOCATE(PTR,TYPE,SIZE) { \ 28 PTR = (TYPE *) ohana_malloc (__FILE__, __LINE__, __func__, (SIZE), sizeof(TYPE)); \ 29 } 29 30 30 # else 31 # define ohana_memregister(X) /* NOP */ 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 46 # define FREE(PTR) { if (PTR != NULL) { ohana_free (__FILE__, __LINE__, __func__, PTR); } } 47 # define free(PTR) { ohana_free(__FILE__, __LINE__, __func__, PTR); } 48 49 # else /* below: not OHANA_MEMORY */ 50 32 51 # define ohana_memcheck(X) /* NOP */ 33 52 # define ohana_memdump(X) /* NOP */ 34 # endif /* OHANA_MEMORY */ 53 void real_free (void *in); 35 54 36 # ifndef ALLOCATE37 55 # define ALLOCATE(PTR,TYPE,SIZE) { \ 38 56 PTR = (TYPE *) malloc ((size_t)(MAX(((SIZE)*((int)sizeof(TYPE))),1))); \ … … 63 81 64 82 # define FREE(PTR) { if (PTR != NULL) { free (PTR); } } 65 # endif /* ALLOCATE*/83 # endif /* OHANA_MEMORY */ 66 84 67 85 # endif /* OHANA_ALLOCATE */
Note:
See TracChangeset
for help on using the changeset viewer.
