IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 31, 2011, 3:50:46 PM (15 years ago)
Author:
eugene
Message:

added test for ohana_memory functions; updated CommandOps to fix interaction between ohana and readline; ohana memory seems to work

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20110505/Ohana/src/libohana/include/ohana_allocate.h

    r31589 r31591  
    11# ifndef OHANA_ALLOCATE
    22# define OHANA_ALLOCATE
     3
     4typedef 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
     12OhanaMemstats ohana_memstats (int mode);
    313
    414/* default is to use basic system memory functions */
    515# ifdef OHANA_MEMORY
    616
    7 void *ohana_malloc (char *file, int line, char *func, int Nelem, size_t esize);
    8 void *ohana_realloc (char *file, int line, char *func, void *in, int Nelem, size_t esize);
    9 void  ohana_free (char *file, int line, char *func, void *in);
     17void *ohana_malloc (const char *file, int line, const char *func, int Nelem, size_t esize);
     18void *ohana_realloc (const char *file, int line, const char *func, void *in, int Nelem, size_t esize);
     19void  ohana_free (const char *file, int line, const char *func, void *in);
    1020void  ohana_memdump_func (int mode);
    1121void  ohana_memcheck_func (int mode);
     22void  real_free (void *in);
    1223
    1324# define ohana_memcheck(X) ohana_memcheck_func (X);
    1425# define ohana_memdump(X) ohana_memdump_func (X);
    1526
    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
    2546# 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); }
    2848
    29 # else  /* OHANA_MEMORY */
     49# else  /* below: not OHANA_MEMORY */
    3050
    3151# define ohana_memcheck(X) /* NOP */
    3252# define ohana_memdump(X) /* NOP */
    33 # define real_free(PTR) { if (PTR) { free(PTR); }}
     53void  real_free (void *in);
    3454
    35 # ifndef ALLOCATE
    3655# define ALLOCATE(PTR,TYPE,SIZE) {                                      \
    3756  PTR = (TYPE *) malloc ((size_t)(MAX(((SIZE)*((int)sizeof(TYPE))),1))); \
     
    6281
    6382# define FREE(PTR) { if (PTR != NULL) { free (PTR); } }
    64 # endif /* ALLOCATE */
    6583# endif /* OHANA_MEMORY */
    6684
Note: See TracChangeset for help on using the changeset viewer.