ccutil/memry.h

Go to the documentation of this file.
00001 
00020 #ifndef           MEMRY_H
00021 #define           MEMRY_H
00022 
00023 #include          <stddef.h>
00024 #include          "host.h"
00025 
00026 #define JUSTCHECKS      0        /*just check consistency */
00027 #define MEMCHECKS     1          /*report totals */
00028 #define FULLMEMCHECKS   2        /*report on all blocks */
00029 
00030 #ifdef __MSW32__
00031 #define NEWDELETE                            /*replace new & delete*/\
00032    void              *operator new(          /*fast allocator*/\
00033    size_t               size,                /*size of object*/\
00034    const char*          file=NULL,              /*filename*/\
00035    INT32             line=0)                 /*line number*/\
00036    {\
00037       return alloc_struct(size);                /*simple to do*/\
00038    }\
00039 \
00040    void              operator delete(        /*fast destructor*/\
00041    void              *deadstruct,            /*thing to free*/\
00042    size_t               size)                /*sizeof struct*/\
00043    {\
00044       free_struct(deadstruct,size);             /*free it*/\
00045    }\
00046 
00047 #define NEWDELETE2(name)                        /*replace new & delete*/\
00048    void              *operator new(          /*fast allocator*/\
00049    size_t               size,                /*size of object*/\
00050    const char*          file=NULL,              /*filename*/\
00051    INT32             line=0)                 /*line number*/\
00052    {\
00053       return alloc_struct(size,#name);          /*simple to do*/\
00054    }\
00055 \
00056    void              operator delete(        /*fast destructor*/\
00057    void              *deadstruct,            /*thing to free*/\
00058    size_t               size)                /*sizeof struct*/\
00059    {\
00060       free_struct(deadstruct,size,#name);          /*free it*/\
00061    }\
00062 
00063 
00064 #undef NEWDELETE
00065 #define NEWDELETE
00066 #undef NEWDELETE2
00067 #define NEWDELETE2(name)
00068 
00069 #else
00070 #define NEWDELETE                            /*replace new & delete*/\
00071    void              *operator new(          /*fast allocator*/\
00072    size_t               size)                /*size of object*/\
00073    {\
00074       return alloc_struct(size);                /*simple to do*/\
00075    }\
00076 \
00077    void              operator delete(        /*fast destructor*/\
00078    void              *deadstruct,            /*thing to free*/\
00079    size_t               size)                /*sizeof struct*/\
00080    {\
00081       free_struct(deadstruct,size);             /*free it*/\
00082    }\
00083 
00084 #define NEWDELETE2(name)                        /*replace new & delete*/\
00085    void              *operator new(          /*fast allocator*/\
00086    size_t               size)                /*size of object*/\
00087    {\
00088       return alloc_struct(size,#name);          /*simple to do*/\
00089    }\
00090 \
00091    void              operator delete(        /*fast destructor*/\
00092    void              *deadstruct,            /*thing to free*/\
00093    size_t               size)                /*sizeof struct*/\
00094    {\
00095       free_struct(deadstruct,size,#name);          /*free it*/\
00096    }\
00097 
00098 #endif
00099 
00103 #define ALLOC_2D_ARRAY(x,y,mem,ptrs,type)          /*make 2d array*/\
00104 { \
00105    INT32             TMP_i; \
00106    mem=(type*)alloc_mem((x)*(y)*sizeof(type));        /*get memory*/\
00107    ptrs=(type**)alloc_mem((x)*sizeof(type*));         /*get ptrs*/\
00108    for (TMP_i=0;TMP_i<(x);TMP_i++)\
00109       ptrs[TMP_i]=mem+(y)*TMP_i;                /*set ptrs*/\
00110 } \
00111 
00112 
00115 #define FREE_2D_ARRAY(mem,ptrs)                    /*free a 2D array*/\
00116 { \
00117    free_mem(mem);                            /*free the memory*/\
00118    free_mem(ptrs);                              /*and the ptrs*/\
00119 } \
00120 
00121 
00125 #define ALLOC_BIG_2D_ARRAY(x,y,mem,ptrs,type)         /*make 2d array*/\
00126 { \
00127    INT32             TMP_i; \
00128    mem=(type*)alloc_big_mem((x)*(y)*sizeof(type));    /*get memory*/\
00129    ptrs=(type**)alloc_big_mem((x)*sizeof(type*));     /*get ptrs*/\
00130    for (TMP_i=0;TMP_i<(x);TMP_i++)\
00131       ptrs[TMP_i]=mem+(y)*TMP_i;                /*set ptrs*/\
00132 } \
00133 
00134 
00137 #define FREE_BIG_2D_ARRAY(mem,ptrs)                /*free a 2D array*/\
00138 { \
00139    free_big_mem(mem);                           /*free the memory*/\
00140    free_big_mem(ptrs);                          /*and the ptrs*/\
00141 } \
00142 
00143 extern DLLSYM void check_mem(                     //check consistency
00144                              const char *string,  //context message
00145                              INT8 level           //level of check
00146                             );
00147                                  //allocate string
00148 extern DLLSYM char *alloc_string(INT32 count  //no of chars required
00149                                 );
00150 extern DLLSYM void free_string(              //free a string
00151                                char *string  //string to free
00152                               );
00153                                  //allocate memory
00154 extern DLLSYM void *alloc_struct (
00155 INT32 count,                     //no of chars required
00156 const char *name = NULL          //class name
00157 );
00158 extern DLLSYM void free_struct ( //free a structure
00159 void *deadstruct,                //structure to free
00160 INT32 count,                     //no of bytes
00161 const char *name = NULL          //class name
00162 );
00163 extern DLLSYM void *alloc_mem_p(             //allocate permanent space
00164                                 INT32 count  //block size to allocate
00165                                );
00166 extern DLLSYM void *alloc_mem(             //get some memory
00167                               INT32 count  //no of bytes to get
00168                              );
00169                                  //get some memory
00170 extern DLLSYM void *alloc_big_mem(INT32 count  //no of bytes to get
00171                                  );
00172                                  //get some memory
00173 extern DLLSYM void *alloc_big_zeros(INT32 count  //no of bytes to get
00174                                    );
00175 extern DLLSYM void free_mem(                //free mem from alloc_mem
00176                             void *oldchunk  //chunk to free
00177                            );
00178 extern DLLSYM void free_big_mem(                //free mem from alloc_mem
00179                                 void *oldchunk  //chunk to free
00180                                );
00181 #endif

Generated on Wed Feb 28 19:49:09 2007 for Tesseract by  doxygen 1.5.1