47 #pragma warning( disable : 4127) 48 #pragma warning( disable : 4706) 52 void qh_fprintf(FILE *fp,
int msgcode,
const char *
fmt, ... );
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,
81 return(*((
const int *)i) - *((
const int *)j));
116 void **freelistp, *newbuffer;
118 int outsize, bufsize;
122 qh_fprintf(qhmem.
ferr, 6235,
"qhull error (qh_memalloc): negative request size (%d). Did int overflow due to high-D?\n", insize);
125 if (insize>=0 && insize <= qhmem.
LASTsize) {
130 if ((
object= *freelistp)) {
133 *freelistp= *((
void **)*freelistp);
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);
156 qhmem.
freemem= (
void *)((
char *)newbuffer+size);
162 qh_fprintf(qhmem.
ferr, 6212,
"qh_memalloc internal error: short totbuffer %d != totshort+totfree... %d\n", qhmem.
totbuffer, n);
179 qh_fprintf(qhmem.
ferr, 6081,
"qhull internal error (qh_memalloc): qhmem has not been initialized.\n");
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);
204 int i, count, totfree= 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);
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");
215 for (
object= qhmem.
freelists[i];
object;
object= *((
void **)
object))
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);
224 qh_fprintf(qhmem.
ferr, 8144,
"qh_memcheck: total size of freelists totfree is the same as qhmem.totfree\n", totfree);
258 *((
void **)
object)= *freelistp;
289 void *buffer, *nextbuffer;
294 for (buffer= qhmem.
curbuffer; buffer; buffer= nextbuffer) {
295 nextbuffer= *((
void **) buffer);
305 memset((
char *)&qhmem, 0,
sizeof(qhmem));
319 memset((
char *)&qhmem, 0,
sizeof(qhmem));
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));
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));
354 qh_fprintf(qhmem.
ferr, 6085,
"qhull internal error (qh_meminit): memory alignment %d is not a power of 2\n", alignment);
357 qhmem.
sizetable= (
int *) calloc((
size_t)numsizes,
sizeof(int));
358 qhmem.
freelists= (
void **) calloc((
size_t)numsizes,
sizeof(
void *));
360 qh_fprintf(qhmem.
ferr, 6086,
"qhull error (qh_meminit): insufficient memory\n");
364 qh_fprintf(qhmem.
ferr, 8059,
"qh_meminitbuffers: memory initialized with alignment %d\n", alignment);
379 qh_fprintf(qhmem.
ferr, 6087,
"qhull error (qh_memsetup): largest mem size %d is >= buffer size %d or initial buffer size %d\n",
384 qh_fprintf(qhmem.
ferr, 6088,
"qhull error (qh_memsetup): insufficient memory\n");
390 for (k=0; k <= qhmem.
LASTsize; k++) {
408 qh_fprintf(qhmem.
ferr, 6089,
"qhull error (qh_memsize): called after qhmem_setup\n");
419 qh_fprintf(qhmem.
ferr, 7060,
"qhull warning (memsize): free list table has room for only %d sizes\n", qhmem.
NUMsizes);
438 %7d quick allocations\n\ 439 %7d short allocations\n\ 440 %7d long allocations\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",
458 qh_fprintf(fp, 9279,
"%7d calls to qh_setlarger\n%7.2g average copy size\n",
460 qh_fprintf(fp, 9280,
" freelists(bytes->count):");
464 for (
object= qhmem.
freelists[i];
object;
object= *((
void **)
object))
486 if (!(
object=
qh_malloc((
size_t)insize))) {
487 qh_fprintf(qhmem.
ferr, 6090,
"qhull error (qh_memalloc): insufficient memory\n");
513 memset((
char *)&qhmem, 0,
sizeof(qhmem));
518 memset((
char *)&qhmem, 0,
sizeof(qhmem));
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));
529 void qh_meminitbuffers(
int tracelevel,
int alignment,
int numsizes,
int bufsize,
int bufinit) {
545 %7d long allocations\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",
568 void qh_memtotal(
int *totlong,
int *curlong,
int *totshort,
int *curshort,
int *maxlong,
int *totbuffer) {
void qh_meminit(FILE *ferr)
void qh_errexit(int exitcode, facetT *, ridgeT *)
void qh_fprintf_stderr(int msgcode, const char *fmt,...)
static int qh_intcompare(const void *i, const void *j)
void qh_memfreeshort(int *curlong, int *totlong)
void qh_fprintf(FILE *fp, int msgcode, const char *fmt,...)
void * qh_malloc(size_t size)
void qh_meminitbuffers(int tracelevel, int alignment, int numsizes, int bufsize, int bufinit)
void qh_memsize(int size)
void qh_memfree(void *object, int insize)
void qh_exit(int exitcode)
void * qh_memalloc(int insize)
void qh_memstatistics(FILE *fp)
void qh_memtotal(int *totlong, int *curlong, int *totshort, int *curshort, int *maxlong, int *totbuffer)