IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 22, 2011, 12:33:45 AM (15 years ago)
Author:
eugene
Message:

merged from eam_branches/ipp-20110505: allow managed memory (with linked list a la psLib); add csv to mana; allow read-only dvo databases

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/libohana/include/ohana_allocate.h

    r30726 r31663  
    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, 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);
     17void *ohana_malloc (const char *file, int line, const char *func, size_t Nelem, size_t esize);
     18void *ohana_realloc (const char *file, int line, const char *func, void *in, size_t Nelem, size_t esize);
     19void  ohana_free (const char *file, int line, const char *func, void *in);
    1120void  ohana_memdump_func (int mode);
    1221void  ohana_memcheck_func (int mode);
     22void  real_free (void *in);
    1323
    14 # define ohana_memregister(X) ohana_memregister_func (__FILE__, __LINE__, (X));
    1524# define ohana_memcheck(X) ohana_memcheck_func (X);
    1625# define ohana_memdump(X) ohana_memdump_func (X);
    1726
    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  }
    2930
    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
    3251# define ohana_memcheck(X) /* NOP */
    3352# define ohana_memdump(X) /* NOP */
    34 # endif /* OHANA_MEMORY */
     53void  real_free (void *in);
    3554
    36 # ifndef ALLOCATE
    3755# define ALLOCATE(PTR,TYPE,SIZE) {                                      \
    3856  PTR = (TYPE *) malloc ((size_t)(MAX(((SIZE)*((int)sizeof(TYPE))),1))); \
     
    6381
    6482# define FREE(PTR) { if (PTR != NULL) { free (PTR); } }
    65 # endif /* ALLOCATE */
     83# endif /* OHANA_MEMORY */
    6684
    6785# endif /* OHANA_ALLOCATE */
Note: See TracChangeset for help on using the changeset viewer.