libmove3d  3.13.0
/home/slemaign/softs-local/BioMove3D-git/graspPlanning/qhull/mem.h
00001 /*<html><pre>  -<a                             href="qh-mem.htm"
00002   >-------------------------------</a><a name="TOP">-</a>
00003 
00004    mem.h
00005      prototypes for memory management functions
00006 
00007    see qh-mem.htm, mem.c and qset.h
00008 
00009    for error handling, writes message and calls
00010      qh_errexit(qhmem_ERRmem, NULL, NULL) if insufficient memory
00011        and
00012      qh_errexit(qhmem_ERRqhull, NULL, NULL) otherwise
00013 
00014    copyright (c) 1993-2010 The Geometry Center.
00015    $Id: //product/qhull/main/rel/src/mem.h#28 $$Change: 1164 $
00016    $DateTime: 2010/01/07 21:52:00 $$Author: bbarber $
00017 */
00018 
00019 #ifndef qhDEFmem
00020 #define qhDEFmem 1
00021 
00022 #include <stdio.h>
00023 
00024 /*-<a                             href="qh-mem.htm#TOC"
00025   >-------------------------------</a><a name="NOmem">-</a>
00026 
00027   qh_NOmem
00028     turn off quick-fit memory allocation
00029 
00030   notes:
00031     mem.c implements Quickfit memory allocation for about 20% time
00032     savings.  If it fails on your machine, try to locate the
00033     problem, and send the answer to qhull@qhull.org.  If this can
00034     not be done, define qh_NOmem to use malloc/free instead.
00035 
00036    #define qh_NOmem
00037 */
00038 
00039 /*-<a                             href="qh-mem.htm#TOC"
00040 >-------------------------------</a><a name="TRACEshort">-</a>
00041 
00042 qh_TRACEshort
00043 Trace short and quick memory allocations at T5
00044 
00045 */
00046 #define qh_TRACEshort
00047 
00048 /*-------------------------------------------
00049     to avoid bus errors, memory allocation must consider alignment requirements.
00050     malloc() automatically takes care of alignment.   Since mem.c manages
00051     its own memory, we need to explicitly specify alignment in
00052     qh_meminitbuffers().
00053 
00054     A safe choice is sizeof(double).  sizeof(float) may be used if doubles
00055     do not occur in data structures and pointers are the same size.  Be careful
00056     of machines (e.g., DEC Alpha) with large pointers.  If gcc is available,
00057     use __alignof__(double) or fmax_(__alignof__(float), __alignof__(void *)).
00058 
00059    see <a href="user.h#MEMalign">qh_MEMalign</a> in user.h for qhull's alignment
00060 */
00061 
00062 #define qhmem_ERRmem 4    /* matches qh_ERRmem in libqhull.h */
00063 #define qhmem_ERRqhull 5  /* matches qh_ERRqhull in libqhull.h */
00064 
00065 /*-<a                             href="qh-mem.htm#TOC"
00066   >--------------------------------</a><a name="ptr_intT">-</a>
00067 
00068   ptr_intT
00069     for casting a void * to an integer-type that holds a pointer
00070     Used for integer expressions (e.g., computing qh_gethash() in poly.c)
00071 
00072   notes:
00073     WARN64 -- these notes indicate 64-bit issues
00074     On 64-bit machines, a pointer may be larger than an 'int'.
00075     qh_meminit()/mem.c checks that 'ptr_intT' holds a 'void*'
00076     ptr_intT is not defined as 'long long' for portability to older compilers
00077     ptr_intT is typically a signed value, but not necessarily so
00078     size_t is typically unsigned, but should match the parameter type
00079     Qhull uses int instead of size_t except for system calls such as malloc, qsort, qh_malloc, etc.
00080     This matches Qt convention and is easier to work with.  
00081 */
00082 typedef long ptr_intT;
00083 
00084 /*-<a                             href="qh-mem.htm#TOC"
00085   >--------------------------------</a><a name="qhmemT">-</a>
00086 
00087   qhmemT
00088     global memory structure for mem.c
00089 
00090  notes:
00091    users should ignore qhmem except for writing extensions
00092    qhmem is allocated in mem.c
00093 
00094    qhmem could be swapable like qh and qhstat, but then
00095    multiple qh's and qhmem's would need to keep in synch.
00096    A swapable qhmem would also waste memory buffers.  As long
00097    as memory operations are atomic, there is no problem with
00098    multiple qh structures being active at the same time.
00099    If you need separate address spaces, you can swap the
00100    contents of qhmem.
00101 */
00102 typedef struct qhmemT qhmemT;
00103 extern qhmemT qhmem;
00104 
00105 #ifndef DEFsetT
00106 #define DEFsetT 1
00107 typedef struct setT setT;          /* defined in qset.h */
00108 #endif
00109 
00110 /* Update qhmem in mem.c if add or remove fields */
00111 struct qhmemT {               /* global memory management variables */
00112   int      BUFsize;           /* size of memory allocation buffer */
00113   int      BUFinit;           /* initial size of memory allocation buffer */
00114   int      TABLEsize;         /* actual number of sizes in free list table */
00115   int      NUMsizes;          /* maximum number of sizes in free list table */
00116   int      LASTsize;          /* last size in free list table */
00117   int      ALIGNmask;         /* worst-case alignment, must be 2^n-1 */
00118   void   **freelists;          /* free list table, linked by offset 0 */
00119   int     *sizetable;         /* size of each freelist */
00120   int     *indextable;        /* size->index table */
00121   void    *curbuffer;         /* current buffer, linked by offset 0 */
00122   void    *freemem;           /*   free memory in curbuffer */
00123   int      freesize;          /*   size of freemem in bytes */
00124   setT    *tempstack;         /* stack of temporary memory, managed by users */
00125   FILE    *ferr;              /* file for reporting errors, only user is qh_fprintf() */
00126   int      IStracing;         /* =5 if tracing memory allocations */
00127   int      cntquick;          /* count of quick allocations */
00128                               /* Note: removing statistics doesn't effect speed */
00129   int      cntshort;          /* count of short allocations */
00130   int      cntlong;           /* count of long allocations */
00131   int      freeshort;         /* count of short memfrees */
00132   int      freelong;          /* count of long memfrees */
00133   int      totbuffer;         /* total short memory buffers minus buffer links */
00134   int      totdropped;        /* total dropped memory at end of short memory buffers (e.g., freesize) */
00135   int      totfree;           /* total size of free, short memory on freelists */
00136   int      totlong;           /* total size of long memory in use */
00137   int      maxlong;           /*   maximum totlong */
00138   int      totshort;          /* total size of short memory in use */
00139   int      totunused;         /* total unused short memory (estimated, short size - request size of first allocations) */
00140   int      cntlarger;         /* count of setlarger's */
00141   int      totlarger;         /* total copied by setlarger */
00142 };
00143 
00144 
00145 /*==================== -macros ====================*/
00146 
00147 /*-<a                             href="qh-mem.htm#TOC"
00148   >--------------------------------</a><a name="memalloc_">-</a>
00149 
00150   qh_memalloc_(insize, object, type)
00151     returns object of size bytes
00152         assumes size<=qhmem.LASTsize and void **freelistp is a temp
00153 */
00154 
00155 #if defined qh_NOmem
00156 #define qh_memalloc_(insize, freelistp, object, type) {\
00157   object= (type*)qh_memalloc(insize); }
00158 #elif defined qh_TRACEshort
00159 #define qh_memalloc_(insize, freelistp, object, type) {\
00160     freelistp= NULL; /* Avoid warnings */ \
00161     object= (type*)qh_memalloc(insize); }
00162 #else /* !qh_NOmem */
00163 
00164 #define qh_memalloc_(insize, freelistp, object, type) {\
00165   freelistp= qhmem.freelists + qhmem.indextable[insize];\
00166   if ((object= (type*)*freelistp)) {\
00167     qhmem.totshort += qhmem.sizetable[qhmem.indextable[insize]]; \
00168     qhmem.totfree -= qhmem.sizetable[qhmem.indextable[insize]]; \
00169     qhmem.cntquick++;  \
00170     *freelistp= *((void **)*freelistp);\
00171   }else object= (type*)qh_memalloc(insize);}
00172 #endif
00173 
00174 /*-<a                             href="qh-mem.htm#TOC"
00175   >--------------------------------</a><a name="memfree_">-</a>
00176 
00177   qh_memfree_(object, insize)
00178     free up an object
00179 
00180   notes:
00181     object may be NULL
00182     assumes size<=qhmem.LASTsize and void **freelistp is a temp
00183 */
00184 #if defined qh_NOmem
00185 #define qh_memfree_(object, insize, freelistp) {\
00186   qh_memfree(object, insize); }
00187 #elif defined qh_TRACEshort
00188 #define qh_memfree_(object, insize, freelistp) {\
00189     freelistp= NULL; /* Avoid warnings */ \
00190     qh_memfree(object, insize); }
00191 #else /* !qh_NOmem */
00192 
00193 #define qh_memfree_(object, insize, freelistp) {\
00194   if (object) { \
00195     qhmem .freeshort++;\
00196     freelistp= qhmem.freelists + qhmem.indextable[insize];\
00197     qhmem.totshort -= qhmem.sizetable[qhmem.indextable[insize]]; \
00198     qhmem.totfree += qhmem.sizetable[qhmem.indextable[insize]]; \
00199     *((void **)object)= *freelistp;\
00200     *freelistp= object;}}
00201 #endif
00202 
00203 /*=============== prototypes in alphabetical order ============*/
00204 
00205 void *qh_memalloc(int insize);
00206 void qh_memfree(void *object, int insize);
00207 void qh_memfreeshort(int *curlong, int *totlong);
00208 void qh_meminit(FILE *ferr);
00209 void qh_meminitbuffers(int tracelevel, int alignment, int numsizes,
00210                         int bufsize, int bufinit);
00211 void qh_memsetup(void);
00212 void qh_memsize(int size);
00213 void qh_memstatistics(FILE *fp);
00214 void qh_memtotal(int *totlong, int *curlong, int *totshort, int *curshort, int *maxlong, int *totbuffer);
00215 
00216 #endif /* qhDEFmem */
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines