mem.c
Go to the documentation of this file.
1 /*<html><pre> -<a href="qh-mem.htm"
2  >-------------------------------</a><a name="TOP">-</a>
3 
4  mem.c
5  memory management routines for qhull
6 
7  This is a standalone program.
8 
9  To initialize memory:
10 
11  qh_meminit(stderr);
12  qh_meminitbuffers(qh IStracing, qh_MEMalign, 7, qh_MEMbufsize,qh_MEMinitbuf);
13  qh_memsize((int)sizeof(facetT));
14  qh_memsize((int)sizeof(facetT));
15  ...
16  qh_memsetup();
17 
18  To free up all memory buffers:
19  qh_memfreeshort(&curlong, &totlong);
20 
21  if qh_NOmem,
22  malloc/free is used instead of mem.c
23 
24  notes:
25  uses Quickfit algorithm (freelists for commonly allocated sizes)
26  assumes small sizes for freelists (it discards the tail of memory buffers)
27 
28  see:
29  qh-mem.htm and mem.h
30  global.c (qh_initbuffers) for an example of using mem.c
31 
32  Copyright (c) 1993-2015 The Geometry Center.
33  $Id: //main/2015/qhull/src/libqhull/mem.c#7 $$Change: 2065 $
34  $DateTime: 2016/01/18 13:51:04 $$Author: bbarber $
35 */
36 
37 #include "user.h" /* for QHULL_CRTDBG */
38 #include "mem.h"
39 #include <string.h>
40 #include <stdio.h>
41 #include <stdlib.h>
42 
43 #ifndef qhDEFlibqhull
44 typedef struct ridgeT ridgeT;
45 typedef struct facetT facetT;
46 #ifdef _MSC_VER /* Microsoft Visual C++ -- warning level 4 */
47 #pragma warning( disable : 4127) /* conditional expression is constant */
48 #pragma warning( disable : 4706) /* assignment within conditional function */
49 #endif
50 void qh_errexit(int exitcode, facetT *, ridgeT *);
51 void qh_exit(int exitcode);
52 void qh_fprintf(FILE *fp, int msgcode, const char *fmt, ... );
53 void qh_fprintf_stderr(int msgcode, const char *fmt, ... );
54 void qh_free(void *mem);
55 void *qh_malloc(size_t size);
56 #endif
57 
58 /*============ -global data structure ==============
59  see mem.h for definition
60 */
61 
62 qhmemT qhmem= {0,0,0,0,0,0,0,0,0,0,0,
63  0,0,0,0,0,0,0,0,0,0,0,
64  0,0,0,0,0,0,0}; /* remove "= {0}" if this causes a compiler error */
65 
66 #ifndef qh_NOmem
67 
68 /*============= internal functions ==============*/
69 
70 static int qh_intcompare(const void *i, const void *j);
71 
72 /*========== functions in alphabetical order ======== */
73 
74 /*-<a href="qh-mem.htm#TOC"
75  >-------------------------------</a><a name="intcompare">-</a>
76 
77  qh_intcompare( i, j )
78  used by qsort and bsearch to compare two integers
79 */
80 static int qh_intcompare(const void *i, const void *j) {
81  return(*((const int *)i) - *((const int *)j));
82 } /* intcompare */
83 
84 
85 /*-<a href="qh-mem.htm#TOC"
86  >--------------------------------</a><a name="memalloc">-</a>
87 
88  qh_memalloc( insize )
89  returns object of insize bytes
90  qhmem is the global memory structure
91 
92  returns:
93  pointer to allocated memory
94  errors if insufficient memory
95 
96  notes:
97  use explicit type conversion to avoid type warnings on some compilers
98  actual object may be larger than insize
99  use qh_memalloc_() for inline code for quick allocations
100  logs allocations if 'T5'
101  caller is responsible for freeing the memory.
102  short memory is freed on shutdown by qh_memfreeshort unless qh_NOmem
103 
104  design:
105  if size < qhmem.LASTsize
106  if qhmem.freelists[size] non-empty
107  return first object on freelist
108  else
109  round up request to size of qhmem.freelists[size]
110  allocate new allocation buffer if necessary
111  allocate object from allocation buffer
112  else
113  allocate object with qh_malloc() in user.c
114 */
115 void *qh_memalloc(int insize) {
116  void **freelistp, *newbuffer;
117  int idx, size, n;
118  int outsize, bufsize;
119  void *object;
120 
121  if (insize<0) {
122  qh_fprintf(qhmem.ferr, 6235, "qhull error (qh_memalloc): negative request size (%d). Did int overflow due to high-D?\n", insize); /* WARN64 */
123  qh_errexit(qhmem_ERRmem, NULL, NULL);
124  }
125  if (insize>=0 && insize <= qhmem.LASTsize) {
126  idx= qhmem.indextable[insize];
127  outsize= qhmem.sizetable[idx];
128  qhmem.totshort += outsize;
129  freelistp= qhmem.freelists+idx;
130  if ((object= *freelistp)) {
131  qhmem.cntquick++;
132  qhmem.totfree -= outsize;
133  *freelistp= *((void **)*freelistp); /* replace freelist with next object */
134 #ifdef qh_TRACEshort
135  n= qhmem.cntshort+qhmem.cntquick+qhmem.freeshort;
136  if (qhmem.IStracing >= 5)
137  qh_fprintf(qhmem.ferr, 8141, "qh_mem %p n %8d alloc quick: %d bytes (tot %d cnt %d)\n", object, n, outsize, qhmem.totshort, qhmem.cntshort+qhmem.cntquick-qhmem.freeshort);
138 #endif
139  return(object);
140  }else {
141  qhmem.cntshort++;
142  if (outsize > qhmem.freesize) {
143  qhmem.totdropped += qhmem.freesize;
144  if (!qhmem.curbuffer)
145  bufsize= qhmem.BUFinit;
146  else
147  bufsize= qhmem.BUFsize;
148  if (!(newbuffer= qh_malloc((size_t)bufsize))) {
149  qh_fprintf(qhmem.ferr, 6080, "qhull error (qh_memalloc): insufficient memory to allocate short memory buffer (%d bytes)\n", bufsize);
150  qh_errexit(qhmem_ERRmem, NULL, NULL);
151  }
152  *((void **)newbuffer)= qhmem.curbuffer; /* prepend newbuffer to curbuffer
153  list. newbuffer!=0 by QH6080 */
154  qhmem.curbuffer= newbuffer;
155  size= (sizeof(void **) + qhmem.ALIGNmask) & ~qhmem.ALIGNmask;
156  qhmem.freemem= (void *)((char *)newbuffer+size);
157  qhmem.freesize= bufsize - size;
158  qhmem.totbuffer += bufsize - size; /* easier to check */
159  /* Periodically test totbuffer. It matches at beginning and exit of every call */
160  n = qhmem.totshort + qhmem.totfree + qhmem.totdropped + qhmem.freesize - outsize;
161  if (qhmem.totbuffer != n) {
162  qh_fprintf(qhmem.ferr, 6212, "qh_memalloc internal error: short totbuffer %d != totshort+totfree... %d\n", qhmem.totbuffer, n);
163  qh_errexit(qhmem_ERRmem, NULL, NULL);
164  }
165  }
166  object= qhmem.freemem;
167  qhmem.freemem= (void *)((char *)qhmem.freemem + outsize);
168  qhmem.freesize -= outsize;
169  qhmem.totunused += outsize - insize;
170 #ifdef qh_TRACEshort
171  n= qhmem.cntshort+qhmem.cntquick+qhmem.freeshort;
172  if (qhmem.IStracing >= 5)
173  qh_fprintf(qhmem.ferr, 8140, "qh_mem %p n %8d alloc short: %d bytes (tot %d cnt %d)\n", object, n, outsize, qhmem.totshort, qhmem.cntshort+qhmem.cntquick-qhmem.freeshort);
174 #endif
175  return object;
176  }
177  }else { /* long allocation */
178  if (!qhmem.indextable) {
179  qh_fprintf(qhmem.ferr, 6081, "qhull internal error (qh_memalloc): qhmem has not been initialized.\n");
180  qh_errexit(qhmem_ERRqhull, NULL, NULL);
181  }
182  outsize= insize;
183  qhmem.cntlong++;
184  qhmem.totlong += outsize;
185  if (qhmem.maxlong < qhmem.totlong)
186  qhmem.maxlong= qhmem.totlong;
187  if (!(object= qh_malloc((size_t)outsize))) {
188  qh_fprintf(qhmem.ferr, 6082, "qhull error (qh_memalloc): insufficient memory to allocate %d bytes\n", outsize);
189  qh_errexit(qhmem_ERRmem, NULL, NULL);
190  }
191  if (qhmem.IStracing >= 5)
192  qh_fprintf(qhmem.ferr, 8057, "qh_mem %p n %8d alloc long: %d bytes (tot %d cnt %d)\n", object, qhmem.cntlong+qhmem.freelong, outsize, qhmem.totlong, qhmem.cntlong-qhmem.freelong);
193  }
194  return(object);
195 } /* memalloc */
196 
197 
198 /*-<a href="qh-mem.htm#TOC"
199  >--------------------------------</a><a name="memcheck">-</a>
200 
201  qh_memcheck( )
202 */
203 void qh_memcheck(void) {
204  int i, count, totfree= 0;
205  void *object;
206 
207  if (qhmem.ferr == 0 || qhmem.IStracing < 0 || qhmem.IStracing > 10 || (((qhmem.ALIGNmask+1) & qhmem.ALIGNmask) != 0)) {
208  qh_fprintf_stderr(6244, "qh_memcheck error: either qhmem is overwritten or qhmem is not initialized. Call qh_meminit() or qh_new_qhull() before calling qh_mem routines. ferr 0x%x IsTracing %d ALIGNmask 0x%x", qhmem.ferr, qhmem.IStracing, qhmem.ALIGNmask);
209  qh_exit(qhmem_ERRqhull); /* can not use qh_errexit() */
210  }
211  if (qhmem.IStracing != 0)
212  qh_fprintf(qhmem.ferr, 8143, "qh_memcheck: check size of freelists on qhmem\nqh_memcheck: A segmentation fault indicates an overwrite of qhmem\n");
213  for (i=0; i < qhmem.TABLEsize; i++) {
214  count=0;
215  for (object= qhmem.freelists[i]; object; object= *((void **)object))
216  count++;
217  totfree += qhmem.sizetable[i] * count;
218  }
219  if (totfree != qhmem.totfree) {
220  qh_fprintf(qhmem.ferr, 6211, "Qhull internal error (qh_memcheck): totfree %d not equal to freelist total %d\n", qhmem.totfree, totfree);
221  qh_errexit(qhmem_ERRqhull, NULL, NULL);
222  }
223  if (qhmem.IStracing != 0)
224  qh_fprintf(qhmem.ferr, 8144, "qh_memcheck: total size of freelists totfree is the same as qhmem.totfree\n", totfree);
225 } /* memcheck */
226 
227 /*-<a href="qh-mem.htm#TOC"
228  >--------------------------------</a><a name="memfree">-</a>
229 
230  qh_memfree( object, insize )
231  free up an object of size bytes
232  size is insize from qh_memalloc
233 
234  notes:
235  object may be NULL
236  type checking warns if using (void **)object
237  use qh_memfree_() for quick free's of small objects
238 
239  design:
240  if size <= qhmem.LASTsize
241  append object to corresponding freelist
242  else
243  call qh_free(object)
244 */
245 void qh_memfree(void *object, int insize) {
246  void **freelistp;
247  int idx, outsize;
248 
249  if (!object)
250  return;
251  if (insize <= qhmem.LASTsize) {
252  qhmem.freeshort++;
253  idx= qhmem.indextable[insize];
254  outsize= qhmem.sizetable[idx];
255  qhmem.totfree += outsize;
256  qhmem.totshort -= outsize;
257  freelistp= qhmem.freelists + idx;
258  *((void **)object)= *freelistp;
259  *freelistp= object;
260 #ifdef qh_TRACEshort
261  idx= qhmem.cntshort+qhmem.cntquick+qhmem.freeshort;
262  if (qhmem.IStracing >= 5)
263  qh_fprintf(qhmem.ferr, 8142, "qh_mem %p n %8d free short: %d bytes (tot %d cnt %d)\n", object, idx, outsize, qhmem.totshort, qhmem.cntshort+qhmem.cntquick-qhmem.freeshort);
264 #endif
265  }else {
266  qhmem.freelong++;
267  qhmem.totlong -= insize;
268  if (qhmem.IStracing >= 5)
269  qh_fprintf(qhmem.ferr, 8058, "qh_mem %p n %8d free long: %d bytes (tot %d cnt %d)\n", object, qhmem.cntlong+qhmem.freelong, insize, qhmem.totlong, qhmem.cntlong-qhmem.freelong);
270  qh_free(object);
271  }
272 } /* memfree */
273 
274 
275 /*-<a href="qh-mem.htm#TOC"
276  >-------------------------------</a><a name="memfreeshort">-</a>
277 
278  qh_memfreeshort( curlong, totlong )
279  frees up all short and qhmem memory allocations
280 
281  returns:
282  number and size of current long allocations
283 
284  see:
285  qh_freeqhull(allMem)
286  qh_memtotal(curlong, totlong, curshort, totshort, maxlong, totbuffer);
287 */
288 void qh_memfreeshort(int *curlong, int *totlong) {
289  void *buffer, *nextbuffer;
290  FILE *ferr;
291 
292  *curlong= qhmem.cntlong - qhmem.freelong;
293  *totlong= qhmem.totlong;
294  for (buffer= qhmem.curbuffer; buffer; buffer= nextbuffer) {
295  nextbuffer= *((void **) buffer);
296  qh_free(buffer);
297  }
298  qhmem.curbuffer= NULL;
299  if (qhmem.LASTsize) {
300  qh_free(qhmem.indextable);
301  qh_free(qhmem.freelists);
302  qh_free(qhmem.sizetable);
303  }
304  ferr= qhmem.ferr;
305  memset((char *)&qhmem, 0, sizeof(qhmem)); /* every field is 0, FALSE, NULL */
306  qhmem.ferr= ferr;
307 } /* memfreeshort */
308 
309 
310 /*-<a href="qh-mem.htm#TOC"
311  >--------------------------------</a><a name="meminit">-</a>
312 
313  qh_meminit( ferr )
314  initialize qhmem and test sizeof( void*)
315  Does not throw errors. qh_exit on failure
316 */
317 void qh_meminit(FILE *ferr) {
318 
319  memset((char *)&qhmem, 0, sizeof(qhmem)); /* every field is 0, FALSE, NULL */
320  if (ferr)
321  qhmem.ferr= ferr;
322  else
323  qhmem.ferr= stderr;
324  if (sizeof(void*) < sizeof(int)) {
325  qh_fprintf(qhmem.ferr, 6083, "qhull internal error (qh_meminit): sizeof(void*) %d < sizeof(int) %d. qset.c will not work\n", (int)sizeof(void*), (int)sizeof(int));
326  qh_exit(qhmem_ERRqhull); /* can not use qh_errexit() */
327  }
328  if (sizeof(void*) > sizeof(ptr_intT)) {
329  qh_fprintf(qhmem.ferr, 6084, "qhull internal error (qh_meminit): sizeof(void*) %d > sizeof(ptr_intT) %d. Change ptr_intT in mem.h to 'long long'\n", (int)sizeof(void*), (int)sizeof(ptr_intT));
330  qh_exit(qhmem_ERRqhull); /* can not use qh_errexit() */
331  }
332  qh_memcheck();
333 } /* meminit */
334 
335 /*-<a href="qh-mem.htm#TOC"
336  >-------------------------------</a><a name="meminitbuffers">-</a>
337 
338  qh_meminitbuffers( tracelevel, alignment, numsizes, bufsize, bufinit )
339  initialize qhmem
340  if tracelevel >= 5, trace memory allocations
341  alignment= desired address alignment for memory allocations
342  numsizes= number of freelists
343  bufsize= size of additional memory buffers for short allocations
344  bufinit= size of initial memory buffer for short allocations
345 */
346 void qh_meminitbuffers(int tracelevel, int alignment, int numsizes, int bufsize, int bufinit) {
347 
348  qhmem.IStracing= tracelevel;
349  qhmem.NUMsizes= numsizes;
350  qhmem.BUFsize= bufsize;
351  qhmem.BUFinit= bufinit;
352  qhmem.ALIGNmask= alignment-1;
353  if (qhmem.ALIGNmask & ~qhmem.ALIGNmask) {
354  qh_fprintf(qhmem.ferr, 6085, "qhull internal error (qh_meminit): memory alignment %d is not a power of 2\n", alignment);
355  qh_errexit(qhmem_ERRqhull, NULL, NULL);
356  }
357  qhmem.sizetable= (int *) calloc((size_t)numsizes, sizeof(int));
358  qhmem.freelists= (void **) calloc((size_t)numsizes, sizeof(void *));
359  if (!qhmem.sizetable || !qhmem.freelists) {
360  qh_fprintf(qhmem.ferr, 6086, "qhull error (qh_meminit): insufficient memory\n");
361  qh_errexit(qhmem_ERRmem, NULL, NULL);
362  }
363  if (qhmem.IStracing >= 1)
364  qh_fprintf(qhmem.ferr, 8059, "qh_meminitbuffers: memory initialized with alignment %d\n", alignment);
365 } /* meminitbuffers */
366 
367 /*-<a href="qh-mem.htm#TOC"
368  >-------------------------------</a><a name="memsetup">-</a>
369 
370  qh_memsetup()
371  set up memory after running memsize()
372 */
373 void qh_memsetup(void) {
374  int k,i;
375 
376  qsort(qhmem.sizetable, (size_t)qhmem.TABLEsize, sizeof(int), qh_intcompare);
377  qhmem.LASTsize= qhmem.sizetable[qhmem.TABLEsize-1];
378  if (qhmem.LASTsize >= qhmem.BUFsize || qhmem.LASTsize >= qhmem.BUFinit) {
379  qh_fprintf(qhmem.ferr, 6087, "qhull error (qh_memsetup): largest mem size %d is >= buffer size %d or initial buffer size %d\n",
380  qhmem.LASTsize, qhmem.BUFsize, qhmem.BUFinit);
381  qh_errexit(qhmem_ERRmem, NULL, NULL);
382  }
383  if (!(qhmem.indextable= (int *)qh_malloc((qhmem.LASTsize+1) * sizeof(int)))) {
384  qh_fprintf(qhmem.ferr, 6088, "qhull error (qh_memsetup): insufficient memory\n");
385  qh_errexit(qhmem_ERRmem, NULL, NULL);
386  }
387  for (k=qhmem.LASTsize+1; k--; )
388  qhmem.indextable[k]= k;
389  i= 0;
390  for (k=0; k <= qhmem.LASTsize; k++) {
391  if (qhmem.indextable[k] <= qhmem.sizetable[i])
392  qhmem.indextable[k]= i;
393  else
394  qhmem.indextable[k]= ++i;
395  }
396 } /* memsetup */
397 
398 /*-<a href="qh-mem.htm#TOC"
399  >-------------------------------</a><a name="memsize">-</a>
400 
401  qh_memsize( size )
402  define a free list for this size
403 */
404 void qh_memsize(int size) {
405  int k;
406 
407  if (qhmem.LASTsize) {
408  qh_fprintf(qhmem.ferr, 6089, "qhull error (qh_memsize): called after qhmem_setup\n");
409  qh_errexit(qhmem_ERRqhull, NULL, NULL);
410  }
411  size= (size + qhmem.ALIGNmask) & ~qhmem.ALIGNmask;
412  for (k=qhmem.TABLEsize; k--; ) {
413  if (qhmem.sizetable[k] == size)
414  return;
415  }
416  if (qhmem.TABLEsize < qhmem.NUMsizes)
417  qhmem.sizetable[qhmem.TABLEsize++]= size;
418  else
419  qh_fprintf(qhmem.ferr, 7060, "qhull warning (memsize): free list table has room for only %d sizes\n", qhmem.NUMsizes);
420 } /* memsize */
421 
422 
423 /*-<a href="qh-mem.htm#TOC"
424  >-------------------------------</a><a name="memstatistics">-</a>
425 
426  qh_memstatistics( fp )
427  print out memory statistics
428 
429  Verifies that qhmem.totfree == sum of freelists
430 */
431 void qh_memstatistics(FILE *fp) {
432  int i;
433  int count;
434  void *object;
435 
436  qh_memcheck();
437  qh_fprintf(fp, 9278, "\nmemory statistics:\n\
438 %7d quick allocations\n\
439 %7d short allocations\n\
440 %7d long allocations\n\
441 %7d short frees\n\
442 %7d long frees\n\
443 %7d bytes of short memory in use\n\
444 %7d bytes of short memory in freelists\n\
445 %7d bytes of dropped short memory\n\
446 %7d bytes of unused short memory (estimated)\n\
447 %7d bytes of long memory allocated (max, except for input)\n\
448 %7d bytes of long memory in use (in %d pieces)\n\
449 %7d bytes of short memory buffers (minus links)\n\
450 %7d bytes per short memory buffer (initially %d bytes)\n",
451  qhmem.cntquick, qhmem.cntshort, qhmem.cntlong,
452  qhmem.freeshort, qhmem.freelong,
453  qhmem.totshort, qhmem.totfree,
454  qhmem.totdropped + qhmem.freesize, qhmem.totunused,
455  qhmem.maxlong, qhmem.totlong, qhmem.cntlong - qhmem.freelong,
456  qhmem.totbuffer, qhmem.BUFsize, qhmem.BUFinit);
457  if (qhmem.cntlarger) {
458  qh_fprintf(fp, 9279, "%7d calls to qh_setlarger\n%7.2g average copy size\n",
459  qhmem.cntlarger, ((float)qhmem.totlarger)/(float)qhmem.cntlarger);
460  qh_fprintf(fp, 9280, " freelists(bytes->count):");
461  }
462  for (i=0; i < qhmem.TABLEsize; i++) {
463  count=0;
464  for (object= qhmem.freelists[i]; object; object= *((void **)object))
465  count++;
466  qh_fprintf(fp, 9281, " %d->%d", qhmem.sizetable[i], count);
467  }
468  qh_fprintf(fp, 9282, "\n\n");
469 } /* memstatistics */
470 
471 
472 /*-<a href="qh-mem.htm#TOC"
473  >-------------------------------</a><a name="NOmem">-</a>
474 
475  qh_NOmem
476  turn off quick-fit memory allocation
477 
478  notes:
479  uses qh_malloc() and qh_free() instead
480 */
481 #else /* qh_NOmem */
482 
483 void *qh_memalloc(int insize) {
484  void *object;
485 
486  if (!(object= qh_malloc((size_t)insize))) {
487  qh_fprintf(qhmem.ferr, 6090, "qhull error (qh_memalloc): insufficient memory\n");
488  qh_errexit(qhmem_ERRmem, NULL, NULL);
489  }
490  qhmem.cntlong++;
491  qhmem.totlong += insize;
492  if (qhmem.maxlong < qhmem.totlong)
493  qhmem.maxlong= qhmem.totlong;
494  if (qhmem.IStracing >= 5)
495  qh_fprintf(qhmem.ferr, 8060, "qh_mem %p n %8d alloc long: %d bytes (tot %d cnt %d)\n", object, qhmem.cntlong+qhmem.freelong, insize, qhmem.totlong, qhmem.cntlong-qhmem.freelong);
496  return object;
497 }
498 
499 void qh_memfree(void *object, int insize) {
500 
501  if (!object)
502  return;
503  qh_free(object);
504  qhmem.freelong++;
505  qhmem.totlong -= insize;
506  if (qhmem.IStracing >= 5)
507  qh_fprintf(qhmem.ferr, 8061, "qh_mem %p n %8d free long: %d bytes (tot %d cnt %d)\n", object, qhmem.cntlong+qhmem.freelong, insize, qhmem.totlong, qhmem.cntlong-qhmem.freelong);
508 }
509 
510 void qh_memfreeshort(int *curlong, int *totlong) {
511  *totlong= qhmem.totlong;
512  *curlong= qhmem.cntlong - qhmem.freelong;
513  memset((char *)&qhmem, 0, sizeof(qhmem)); /* every field is 0, FALSE, NULL */
514 }
515 
516 void qh_meminit(FILE *ferr) {
517 
518  memset((char *)&qhmem, 0, sizeof(qhmem)); /* every field is 0, FALSE, NULL */
519  if (ferr)
520  qhmem.ferr= ferr;
521  else
522  qhmem.ferr= stderr;
523  if (sizeof(void*) < sizeof(int)) {
524  qh_fprintf(qhmem.ferr, 6091, "qhull internal error (qh_meminit): sizeof(void*) %d < sizeof(int) %d. qset.c will not work\n", (int)sizeof(void*), (int)sizeof(int));
525  qh_errexit(qhmem_ERRqhull, NULL, NULL);
526  }
527 }
528 
529 void qh_meminitbuffers(int tracelevel, int alignment, int numsizes, int bufsize, int bufinit) {
530 
531  qhmem.IStracing= tracelevel;
532 }
533 
534 void qh_memsetup(void) {
535 
536 }
537 
538 void qh_memsize(int size) {
539 
540 }
541 
542 void qh_memstatistics(FILE *fp) {
543 
544  qh_fprintf(fp, 9409, "\nmemory statistics:\n\
545 %7d long allocations\n\
546 %7d long frees\n\
547 %7d bytes of long memory allocated (max, except for input)\n\
548 %7d bytes of long memory in use (in %d pieces)\n",
549  qhmem.cntlong,
550  qhmem.freelong,
551  qhmem.maxlong, qhmem.totlong, qhmem.cntlong - qhmem.freelong);
552 }
553 
554 #endif /* qh_NOmem */
555 
556 /*-<a href="qh-mem.htm#TOC"
557 >-------------------------------</a><a name="memtotlong">-</a>
558 
559  qh_memtotal( totlong, curlong, totshort, curshort, maxlong, totbuffer )
560  Return the total, allocated long and short memory
561 
562  returns:
563  Returns the total current bytes of long and short allocations
564  Returns the current count of long and short allocations
565  Returns the maximum long memory and total short buffer (minus one link per buffer)
566  Does not error (UsingLibQhull.cpp)
567 */
568 void qh_memtotal(int *totlong, int *curlong, int *totshort, int *curshort, int *maxlong, int *totbuffer) {
569  *totlong= qhmem.totlong;
570  *curlong= qhmem.cntlong - qhmem.freelong;
571  *totshort= qhmem.totshort;
572  *curshort= qhmem.cntshort + qhmem.cntquick - qhmem.freeshort;
573  *maxlong= qhmem.maxlong;
574  *totbuffer= qhmem.totbuffer;
575 } /* memtotlong */
576 
int TABLEsize
Definition: mem.h:119
int NUMsizes
Definition: mem.h:120
int freelong
Definition: mem.h:137
int totunused
Definition: mem.h:144
int cntlong
Definition: mem.h:135
void qh_memsetup(void)
Definition: mem.c:373
long ptr_intT
Definition: mem.h:86
qhmemT qhmem
Definition: mem.c:62
int totdropped
Definition: mem.h:139
int cntlarger
Definition: mem.h:145
void qh_free(void *mem)
Definition: usermem.c:77
int totlarger
Definition: mem.h:146
Definition: mem.h:116
int BUFinit
Definition: mem.h:118
int totshort
Definition: mem.h:143
void qh_meminit(FILE *ferr)
Definition: mem.c:317
void qh_errexit(int exitcode, facetT *, ridgeT *)
Definition: user.c:213
void qh_fprintf_stderr(int msgcode, const char *fmt,...)
Definition: usermem.c:57
#define qhmem_ERRmem
Definition: mem.h:62
int maxlong
Definition: mem.h:142
static int qh_intcompare(const void *i, const void *j)
Definition: mem.c:80
void qh_memfreeshort(int *curlong, int *totlong)
Definition: mem.c:288
void qh_fprintf(FILE *fp, int msgcode, const char *fmt,...)
Definition: userprintf.c:42
void * curbuffer
Definition: mem.h:126
void * qh_malloc(size_t size)
Definition: usermem.c:90
void qh_meminitbuffers(int tracelevel, int alignment, int numsizes, int bufsize, int bufinit)
Definition: mem.c:346
int cntquick
Definition: mem.h:132
#define qhmem_ERRqhull
Definition: mem.h:63
int cntshort
Definition: mem.h:134
int LASTsize
Definition: mem.h:121
int totfree
Definition: mem.h:140
int freesize
Definition: mem.h:128
int ALIGNmask
Definition: mem.h:122
void qh_memsize(int size)
Definition: mem.c:404
int * sizetable
Definition: mem.h:124
int * indextable
Definition: mem.h:125
int totbuffer
Definition: mem.h:138
void qh_memcheck(void)
Definition: mem.c:203
void ** freelists
Definition: mem.h:123
int IStracing
Definition: mem.h:131
int BUFsize
Definition: mem.h:117
void qh_memfree(void *object, int insize)
Definition: mem.c:245
void * freemem
Definition: mem.h:127
void qh_exit(int exitcode)
Definition: usermem.c:38
fmt
Definition: obb.py:126
int totlong
Definition: mem.h:141
FILE * ferr
Definition: mem.h:130
void * qh_memalloc(int insize)
Definition: mem.c:115
void qh_memstatistics(FILE *fp)
Definition: mem.c:431
void qh_memtotal(int *totlong, int *curlong, int *totshort, int *curshort, int *maxlong, int *totbuffer)
Definition: mem.c:568
int freeshort
Definition: mem.h:136


hpp-fcl
Author(s):
autogenerated on Fri Jun 2 2023 02:39:01