39 #ifdef SCIPdebugMessage
40 #define debugMessage SCIPdebugMessage
41 #define errorMessage SCIPerrorMessage
43 #define debugMessage while( FALSE ) printf
44 #define errorMessage printf
45 #define printErrorHeader(f,l) printf("[%s:%d] ERROR: ", f, l)
46 #define printError printf
49 #define warningMessage printf
50 #define printInfo printf
58 #define MAX(x,y) ((x) >= (y) ? (x) : (y))
59 #define MIN(x,y) ((x) <= (y) ? (x) : (y))
72 #if !defined(NDEBUG) && defined(NPARASCIP)
74 typedef struct Memlist MEMLIST;
86 static MEMLIST* memlist =
NULL;
87 static long long memused = 0;
96 MEMLIST* list = memlist;
104 assert(used == memused);
107 #define checkMemlist()
112 void addMemlistEntry(
115 const char* filename,
121 assert(ptr !=
NULL && size > 0);
123 list = (MEMLIST*)malloc(
sizeof(MEMLIST));
124 assert(list !=
NULL);
128 list->filename = strdup(filename);
129 assert(list->filename !=
NULL);
131 list->next = memlist;
133 memused += (
long long)size;
139 void removeMemlistEntry(
141 const char* filename,
152 while( list !=
NULL && ptr != list->ptr )
154 listptr = &(list->next);
159 assert(ptr == list->ptr);
161 *listptr = list->next;
162 memused -= (
long long)list->size;
163 free(list->filename);
169 printError(
"Tried to free unknown pointer <%p>\n", ptr);
182 while( list !=
NULL && ptr != list->ptr )
201 while( list !=
NULL )
203 printInfo(
"%12p %8lld %s:%d\n", list->ptr, (
long long)(list->size), list->filename, list->line);
204 used += (
long long)list->size;
208 if( used != memused )
210 errorMessage(
"Used memory in list sums up to %lld instead of %lld\n", used, memused);
220 if( memlist !=
NULL || memused > 0 )
255 printInfo(
"optimized version of memory shell linked - no memory diagnostics available\n");
265 printInfo(
"optimized version of memory shell linked - no memory leakage check available\n");
283 const char* filename,
289 debugMessage(
"calloc %lld elements of %lld bytes [%s:%d]\n", (
long long) num, (
long long)size, filename, line);
293 ptr = calloc(num, size);
298 printError(
"Insufficient memory for allocation of %lld bytes\n", ((
long long) num) * ((
long long) size));
300 #if !defined(NDEBUG) && defined(NPARASCIP)
302 addMemlistEntry(ptr, num*size, filename, line);
311 const char* filename,
317 debugMessage(
"malloc %lld bytes [%s:%d]\n", (
long long)size, filename, line);
325 printError(
"Insufficient memory for allocation of %lld bytes\n", (
long long) size);
327 #if !defined(NDEBUG) && defined(NPARASCIP)
329 addMemlistEntry(ptr, size, filename, line);
339 const char* filename,
345 #if !defined(NDEBUG) && defined(NPARASCIP)
347 removeMemlistEntry(ptr, filename, line);
351 newptr = realloc(ptr, size);
356 printError(
"Insufficient memory for reallocation of %lld bytes\n", (
long long) size);
358 #if !defined(NDEBUG) && defined(NPARASCIP)
360 addMemlistEntry(newptr, size, filename, line);
377 memset(ptr, 0, size);
391 assert(source !=
NULL);
392 memcpy(ptr, source, size);
408 assert(source !=
NULL);
409 memmove(ptr, source, size);
417 const char* filename,
423 assert(source !=
NULL || size == 0);
435 const char* filename,
441 #if !defined(NDEBUG) && defined(NPARASCIP)
442 removeMemlistEntry(ptr, filename, line);
466 #define CHUNKLENGTH_MIN 1024
467 #define CHUNKLENGTH_MAX 1048576
468 #define STORESIZE_MAX 8192
469 #define GARBAGE_SIZE 256
470 #define ALIGNMENT (sizeof(FREELIST))
560 assert(chunk !=
NULL);
561 assert(chunk->store <= chunk->storeend);
563 return (ptr >= (
void*)(chunk->store) && ptr < (
void*)(chunk->storeend));
582 assert(chkmem !=
NULL);
587 right = chkmem->nchunks-1;
588 while( left <= right )
590 middle = (left+right)/2;
591 assert(0 <= middle && middle < chkmem->nchunks);
592 chunk = chkmem->chunks[middle];
593 assert(chunk !=
NULL);
594 if( ptr < chunk->store )
596 else if( ptr >= chunk->storeend )
613 assert(chkmem !=
NULL);
634 assert(chunk !=
NULL);
635 assert(chunk->store !=
NULL);
636 assert(chunk->storeend == (
void*)((
char*)(chunk->store) + chunk->elemsize * chunk->storesize));
637 assert(chunk->chkmem !=
NULL);
638 assert(chunk->chkmem->elemsize == chunk->elemsize);
640 if( chunk->eagerfree ==
NULL )
641 assert(chunk->nexteager ==
NULL && chunk->preveager ==
NULL);
642 else if( chunk->preveager ==
NULL )
643 assert(chunk->chkmem->firsteager == chunk);
645 if( chunk->nexteager !=
NULL )
646 assert(chunk->nexteager->preveager == chunk);
647 if( chunk->preveager !=
NULL )
648 assert(chunk->preveager->nexteager == chunk);
651 eager = chunk->eagerfree;
652 while( eager !=
NULL )
658 assert(chunk->eagerfreesize == eagerfreesize);
675 assert(chkmem !=
NULL);
676 assert(chkmem->chunks !=
NULL || chkmem->chunkssize == 0);
677 assert(chkmem->nchunks <= chkmem->chunkssize);
684 for( i = 0; i < chkmem->nchunks; ++i )
686 chunk = chkmem->chunks[i];
687 assert(chunk !=
NULL);
691 storesize += chunk->storesize;
692 eagerfreesize += chunk->eagerfreesize;
694 assert(chkmem->nchunks == nchunks);
695 assert(chkmem->storesize == storesize);
696 assert(chkmem->eagerfreesize == eagerfreesize);
698 assert((chkmem->eagerfreesize == 0) ^ (chkmem->firsteager !=
NULL));
700 if( chkmem->firsteager !=
NULL )
701 assert(chkmem->firsteager->preveager ==
NULL);
703 lazy = chkmem->lazyfree;
704 while( lazy !=
NULL )
707 assert(chunk !=
NULL);
708 assert(chunk->chkmem == chkmem);
712 assert(chkmem->lazyfreesize == lazyfreesize);
715 #define checkChunk(chunk)
716 #define checkChkmem(chkmem)
735 assert(chkmem !=
NULL);
736 assert(chkmem->nchunks <= chkmem->chunkssize);
737 assert(chunk !=
NULL);
738 assert(chunk->store !=
NULL);
740 debugMessage(
"linking chunk %p to chunk block %p [elemsize:%d, %d chunks]\n",
741 (
void*)chunk, (
void*)chkmem, chkmem->elemsize, chkmem->nchunks);
745 right = chkmem->nchunks;
746 while( left < right-1 )
748 middle = (left+right)/2;
749 assert(0 <= middle && middle < chkmem->nchunks);
750 assert(left < middle && middle < right);
751 curchunk = chkmem->chunks[middle];
752 assert(curchunk !=
NULL);
753 if( chunk->store < curchunk->store )
757 assert(chunk->store >= curchunk->storeend);
761 assert(-1 <= left && left < chkmem->nchunks);
762 assert(0 <= right && right <= chkmem->nchunks);
763 assert(left+1 == right);
764 assert(left == -1 || chkmem->chunks[left]->storeend <= chunk->store);
765 assert(right == chkmem->nchunks || chunk->storeend <= chkmem->chunks[right]->store);
768 if( chkmem->nchunks == chkmem->chunkssize )
770 chkmem->chunkssize = 2*(chkmem->nchunks+1);
772 if( chkmem->chunks ==
NULL )
775 assert(chkmem->nchunks < chkmem->chunkssize);
776 assert(chkmem->chunks !=
NULL);
779 for( i = chkmem->nchunks; i > right; --i )
781 chkmem->chunks[i] = chkmem->chunks[i-1];
782 chkmem->chunks[i]->arraypos = i;
786 chunk->arraypos = right;
787 chkmem->chunks[right] = chunk;
789 chkmem->storesize += chunk->storesize;
803 assert(chunk !=
NULL);
804 assert(chunk->eagerfree ==
NULL);
805 assert(chunk->nexteager ==
NULL);
806 assert(chunk->preveager ==
NULL);
808 chkmem = chunk->chkmem;
809 assert(chkmem !=
NULL);
810 assert(chkmem->elemsize == chunk->elemsize);
811 assert(0 <= chunk->arraypos && chunk->arraypos < chkmem->nchunks);
812 assert(chkmem->chunks[chunk->arraypos] == chunk);
814 debugMessage(
"unlinking chunk %p from chunk block %p [elemsize:%d, %d chunks]\n",
815 (
void*)chunk, (
void*)chkmem, chkmem->elemsize, chkmem->nchunks);
818 for( i = chunk->arraypos; i < chkmem->nchunks-1; ++i )
820 chkmem->chunks[i] = chkmem->chunks[i+1];
821 chkmem->chunks[i]->arraypos = i;
824 chkmem->storesize -= chunk->storesize;
834 assert(chunk->chkmem == chkmem);
835 assert(chunk->nexteager ==
NULL);
836 assert(chunk->preveager ==
NULL);
838 chunk->nexteager = chkmem->firsteager;
839 chunk->preveager =
NULL;
840 if( chkmem->firsteager !=
NULL )
842 assert(chkmem->firsteager->preveager ==
NULL);
843 chkmem->firsteager->preveager = chunk;
845 chkmem->firsteager = chunk;
854 assert(chunk !=
NULL);
855 assert(chunk->eagerfreesize == 0 || chunk->eagerfreesize == chunk->storesize);
857 if( chunk->nexteager !=
NULL )
858 chunk->nexteager->preveager = chunk->preveager;
859 if( chunk->preveager !=
NULL )
860 chunk->preveager->nexteager = chunk->nexteager;
863 assert(chunk->chkmem->firsteager == chunk);
864 chunk->chkmem->firsteager = chunk->nexteager;
866 chunk->nexteager =
NULL;
867 chunk->preveager =
NULL;
868 chunk->eagerfree =
NULL;
885 assert(chkmem !=
NULL);
887 debugMessage(
"creating new chunk in chunk block %p [elemsize: %d]\n", (
void*)chkmem, chkmem->elemsize);
890 if( chkmem->nchunks == 0 )
891 storesize = chkmem->initchunksize;
893 storesize = 2 * chkmem->lastchunksize;
894 assert(storesize > 0);
898 storesize =
MAX(storesize, 1);
899 chkmem->lastchunksize = storesize;
903 assert( chkmem->elemsize < INT_MAX / storesize );
904 assert(
sizeof(
CHUNK) < UINT_MAX - (
size_t)(storesize * chkmem->elemsize) );
906 if( newchunk ==
NULL )
910 newchunk->store = (
void*) ((
char*) newchunk +
sizeof(
CHUNK));
911 newchunk->storeend = (
void*) ((
char*) newchunk->store + storesize * chkmem->elemsize);
912 newchunk->eagerfree =
NULL;
913 newchunk->nexteager =
NULL;
914 newchunk->preveager =
NULL;
915 newchunk->chkmem = chkmem;
916 newchunk->elemsize = chkmem->elemsize;
917 newchunk->storesize = storesize;
918 newchunk->eagerfreesize = 0;
919 newchunk->arraypos = -1;
921 debugMessage(
"allocated new chunk %p: %d elements with size %lld\n",
922 (
void*)newchunk, newchunk->storesize, (
long long)(newchunk->elemsize));
925 for( i = 0; i < newchunk->storesize - 1; ++i )
927 freelist = (
FREELIST*) ((
char*) (newchunk->store) + i * chkmem->elemsize);
928 freelist->next = (
FREELIST*) ((
char*) (newchunk->store) + (i + 1) * chkmem->elemsize);
931 freelist = (
FREELIST*) ((
char*) (newchunk->store) + (newchunk->storesize - 1) * chkmem->elemsize);
932 freelist->next = chkmem->lazyfree;
933 chkmem->lazyfree = (
FREELIST*) (newchunk->store);
934 chkmem->lazyfreesize += newchunk->storesize;
950 assert(chunk !=
NULL);
964 assert(chunk !=
NULL);
965 assert(chunk->store !=
NULL);
966 assert(chunk->eagerfree !=
NULL);
967 assert(chunk->chkmem !=
NULL);
968 assert(chunk->chkmem->chunks !=
NULL);
969 assert(chunk->chkmem->firsteager !=
NULL);
970 assert(chunk->eagerfreesize == chunk->storesize);
972 debugMessage(
"freeing chunk %p of chunk block %p [elemsize: %d]\n", (
void*)chunk, (
void*)chunk->chkmem, chunk->chkmem->elemsize);
975 chunk->chkmem->eagerfreesize -= chunk->eagerfreesize;
976 assert(chunk->chkmem->eagerfreesize >= 0);
996 assert(chunk !=
NULL);
997 assert(chunk->eagerfree !=
NULL);
998 assert(chunk->eagerfreesize > 0);
999 assert(chunk->chkmem !=
NULL);
1001 debugMessage(
"allocating chunk element in chunk %p [elemsize: %d]\n", (
void*)chunk, chunk->chkmem->elemsize);
1004 ptr = chunk->eagerfree;
1005 chunk->eagerfree = ptr->next;
1006 chunk->eagerfreesize--;
1007 chunk->chkmem->eagerfreesize--;
1009 assert((chunk->eagerfreesize == 0 && chunk->eagerfree ==
NULL)
1010 || (chunk->eagerfreesize != 0 && chunk->eagerfree !=
NULL));
1011 assert(chunk->chkmem->eagerfreesize >= 0);
1014 if( chunk->eagerfree ==
NULL )
1016 assert(chunk->eagerfreesize == 0);
1032 assert(chunk !=
NULL);
1033 assert(chunk->chkmem !=
NULL);
1036 debugMessage(
"freeing chunk element %p of chunk %p [elemsize: %d]\n", (
void*)ptr, (
void*)chunk, chunk->chkmem->elemsize);
1039 if( chunk->eagerfree ==
NULL )
1041 assert(chunk->eagerfreesize == 0);
1046 ((
FREELIST*)ptr)->next = chunk->eagerfree;
1048 chunk->eagerfreesize++;
1049 chunk->chkmem->eagerfreesize++;
1068 if( chkmem ==
NULL )
1071 chkmem->lazyfree =
NULL;
1072 chkmem->chunks =
NULL;
1073 chkmem->firsteager =
NULL;
1074 chkmem->nextchkmem =
NULL;
1075 chkmem->elemsize = size;
1076 chkmem->chunkssize = 0;
1077 chkmem->nchunks = 0;
1078 chkmem->lastchunksize = 0;
1079 chkmem->storesize = 0;
1080 chkmem->lazyfreesize = 0;
1081 chkmem->eagerfreesize = 0;
1082 chkmem->initchunksize = initchunksize;
1083 chkmem->garbagefactor = garbagefactor;
1085 chkmem->filename =
NULL;
1087 chkmem->ngarbagecalls = 0;
1088 chkmem->ngarbagefrees = 0;
1102 assert(chkmem !=
NULL);
1105 for( i = 0; i < chkmem->nchunks; ++i )
1108 chkmem->lazyfree =
NULL;
1109 chkmem->firsteager =
NULL;
1110 chkmem->nchunks = 0;
1111 chkmem->lastchunksize = 0;
1112 chkmem->storesize = 0;
1113 chkmem->lazyfreesize = 0;
1114 chkmem->eagerfreesize = 0;
1123 assert(chkmem !=
NULL);
1124 assert(*chkmem !=
NULL);
1144 assert(chkmem !=
NULL);
1147 if( chkmem->lazyfree ==
NULL )
1149 assert(chkmem->lazyfreesize == 0);
1152 if( chkmem->firsteager !=
NULL )
1161 assert(chkmem->lazyfree !=
NULL);
1162 assert(chkmem->lazyfreesize > 0);
1164 ptr = chkmem->lazyfree;
1165 chkmem->lazyfree = ptr->next;
1166 chkmem->lazyfreesize--;
1185 assert(chkmem !=
NULL);
1187 debugMessage(
"garbage collection for chunk block %p [elemsize: %d]\n", (
void*)chkmem, chkmem->elemsize);
1190 if( chkmem->lazyfreesize + chkmem->eagerfreesize == chkmem->storesize )
1197 chkmem->ngarbagecalls++;
1201 while( chkmem->lazyfree !=
NULL )
1204 lazyfree = chkmem->lazyfree;
1205 chkmem->lazyfree = chkmem->lazyfree->next;
1206 chkmem->lazyfreesize--;
1209 chunk =
findChunk(chkmem, (
void*)lazyfree);
1213 errorMessage(
"chunk for lazy free chunk %p not found in chunk block %p\n", (
void*)lazyfree, (
void*)chkmem);
1216 assert(chunk !=
NULL);
1220 assert(chunk->eagerfreesize > 0);
1222 assert(chkmem->lazyfreesize == 0);
1225 chunk = chkmem->firsteager;
1226 while( chunk !=
NULL && chkmem->nchunks > 1 )
1228 nexteager = chunk->nexteager;
1229 if( chunk->eagerfreesize == chunk->storesize )
1232 chkmem->ngarbagefrees++;
1247 const char* filename,
1251 assert(chkmem !=
NULL);
1252 assert(ptr !=
NULL);
1261 printError(
"pointer %p does not belong to chunk block %p (size: %lld)\n",
1262 ptr, chkmem, (
long long)(chkmem->elemsize));
1267 ((
FREELIST*)ptr)->next = chkmem->lazyfree;
1269 chkmem->lazyfreesize++;
1272 if( chkmem->garbagefactor >= 0 && chkmem->nchunks > 0 && chkmem->lazyfreesize >=
GARBAGE_SIZE
1273 && chkmem->lazyfreesize + chkmem->eagerfreesize
1274 > chkmem->garbagefactor * (
double)(chkmem->storesize) / (
double)(chkmem->nchunks) )
1288 const char* filename,
1295 chkmem =
createChkmem((
int) size, initchunksize, garbagefactor);
1296 if( chkmem ==
NULL )
1299 printError(
"Insufficient memory for chunk block\n");
1301 debugMessage(
"created chunk memory %p [elemsize: %d]\n", (
void*)chkmem, (
int)size);
1309 const char* filename,
1313 debugMessage(
"clearing chunk memory %p [elemsize: %d]\n", (
void*)chkmem, chkmem->elemsize);
1315 if( chkmem !=
NULL )
1320 printError(
"Tried to clear null chunk block\n");
1327 const char* filename,
1331 assert(chkmem !=
NULL);
1333 debugMessage(
"destroying chunk memory %p [elemsize: %d]\n", (
void*)*chkmem, (*chkmem)->elemsize);
1335 if( *chkmem !=
NULL )
1340 printError(
"Tried to destroy null chunk block\n");
1348 const char* filename,
1354 assert(chkmem !=
NULL);
1355 assert((
int)size == chkmem->elemsize);
1362 printError(
"Insufficient memory for new chunk\n");
1364 debugMessage(
"alloced %8lld bytes in %p [%s:%d]\n", (
long long)size, (
void*)ptr, filename, line);
1376 const char* filename,
1382 assert(chkmem !=
NULL);
1383 assert(source !=
NULL);
1384 assert((
int)size == chkmem->elemsize);
1398 const char* filename,
1402 assert(chkmem !=
NULL);
1403 assert((
int)size == chkmem->elemsize);
1405 debugMessage(
"free %8lld bytes in %p [%s:%d]\n", (
long long)chkmem->elemsize, ptr, filename, line);
1410 printError(
"Tried to free null block pointer\n");
1425 debugMessage(
"garbage collection on chunk memory %p [elemsize: %d]\n", (
void*)chkmem, chkmem->elemsize);
1435 long long chkmemused;
1438 assert(chkmem !=
NULL);
1441 for( i = 0; i < chkmem->nchunks; ++i )
1442 chkmemused += (
long long)(chkmem->chunks[i]->elemsize) * (
long long)(chkmem->chunks[i]->storesize);
1456 #define CHKHASH_SIZE 1013
1483 assert(blkmem !=
NULL);
1484 assert(blkmem->chkmemhash !=
NULL);
1488 chkmem = blkmem->chkmemhash[i];
1489 while( chkmem !=
NULL )
1492 chkmem = chkmem->nextchkmem;
1497 #define checkBlkmem(blkmem)
1514 assert(blkmem !=
NULL);
1519 chkmem = blkmem->chkmemhash[i];
1521 chkmem = chkmem->nextchkmem;
1535 return (size % CHKHASH_SIZE);
1543 const char* filename,
1551 if( blkmem !=
NULL )
1554 blkmem->chkmemhash[i] =
NULL;
1555 blkmem->initchunksize = initchunksize;
1556 blkmem->garbagefactor = garbagefactor;
1557 blkmem->memused = 0;
1562 printError(
"Insufficient memory for block memory header\n");
1571 const char* filename,
1579 if( blkmem !=
NULL )
1583 chkmem = blkmem->chkmemhash[i];
1584 while( chkmem !=
NULL )
1586 nextchkmem = chkmem->nextchkmem;
1588 chkmem = nextchkmem;
1590 blkmem->chkmemhash[i] =
NULL;
1592 blkmem->memused = 0;
1597 printError(
"Tried to clear null block memory\n");
1604 const char* filename,
1608 assert(blkmem !=
NULL);
1610 if( *blkmem !=
NULL )
1614 assert(*blkmem ==
NULL);
1619 printError(
"Tried to destroy null block memory\n");
1627 const char* filename,
1635 assert( blkmem !=
NULL );
1642 chkmemptr = &(blkmem->chkmemhash[hashnumber]);
1643 while( *chkmemptr !=
NULL && (*chkmemptr)->elemsize != (
int)size )
1644 chkmemptr = &((*chkmemptr)->nextchkmem);
1647 if( *chkmemptr ==
NULL )
1649 *chkmemptr =
createChkmem((
int)size, blkmem->initchunksize, blkmem->garbagefactor);
1650 if( *chkmemptr ==
NULL )
1653 printError(
"Insufficient memory for chunk block\n");
1658 (*chkmemptr)->line = line;
1667 printError(
"Insufficient memory for new chunk\n");
1669 debugMessage(
"alloced %8lld bytes in %p [%s:%d]\n", (
long long)size, ptr, filename, line);
1671 blkmem->memused += size;
1684 const char* filename,
1692 assert(oldsize == 0);
1698 if( oldsize == newsize )
1702 if( newptr !=
NULL )
1714 const char* filename,
1720 assert(source !=
NULL);
1734 const char* filename,
1741 assert( blkmem !=
NULL );
1749 debugMessage(
"free %8lld bytes in %p [%s:%d]\n", (
long long)size, ptr, filename, line);
1752 assert( blkmem->chkmemhash !=
NULL );
1753 chkmem = blkmem->chkmemhash[hashnumber];
1754 while( chkmem !=
NULL && chkmem->elemsize != (
int)size )
1755 chkmem = chkmem->nextchkmem;
1756 if( chkmem ==
NULL )
1759 printError(
"Tried to free pointer <%p> in block memory <%p> of unknown size %lld\n",
1760 ptr, (
void*)blkmem, (
long long) size);
1763 assert(chkmem->elemsize == (
int)size);
1768 blkmem->memused -= size;
1769 assert(blkmem->memused >= 0);
1771 else if( size != 0 )
1774 printError(
"Tried to free null block pointer\n");
1789 assert(blkmem !=
NULL);
1795 chkmemptr = &blkmem->chkmemhash[i];
1796 while( *chkmemptr !=
NULL )
1799 if( (*chkmemptr)->nchunks == 0 )
1803 nextchkmem = (*chkmemptr)->nextchkmem;
1805 *chkmemptr = nextchkmem;
1808 chkmemptr = &(*chkmemptr)->nextchkmem;
1818 assert(blkmem !=
NULL);
1820 return blkmem->memused;
1831 assert(blkmem !=
NULL);
1837 if( chkmem ==
NULL )
1840 return (
size_t)(chkmem->elemsize);
1850 int nunusedblocks = 0;
1851 int totalnchunks = 0;
1852 int totalneagerchunks = 0;
1853 int totalnelems = 0;
1854 int totalneagerelems = 0;
1855 int totalnlazyelems = 0;
1857 int totalngarbagecalls = 0;
1858 int totalngarbagefrees = 0;
1860 long long allocedmem = 0;
1861 long long freemem = 0;
1866 printInfo(
" ElSize #Chunk #Eag #Elems #EagFr #LazFr #GCl #GFr Free MBytes First Allocator\n");
1868 printInfo(
" ElSize #Chunk #Eag #Elems #EagFr #LazFr Free MBytes\n");
1871 assert(blkmem !=
NULL);
1875 chkmem = blkmem->chkmemhash[i];
1876 while( chkmem !=
NULL )
1881 int neagerchunks = 0;
1882 int neagerelems = 0;
1884 for( c = 0; c < chkmem->nchunks; ++c )
1886 chunk = chkmem->chunks[c];
1887 assert(chunk !=
NULL);
1888 assert(chunk->elemsize == chkmem->elemsize);
1889 assert(chunk->chkmem == chkmem);
1891 nelems += chunk->storesize;
1892 if( chunk->eagerfree !=
NULL )
1895 neagerelems += chunk->eagerfreesize;
1899 assert(nchunks == chkmem->nchunks);
1900 assert(nelems == chkmem->storesize);
1901 assert(neagerelems == chkmem->eagerfreesize);
1906 allocedmem += (
long long)chkmem->elemsize * (
long long)nelems;
1907 freemem += (
long long)chkmem->elemsize * ((
long long)neagerelems + (
long long)chkmem->lazyfreesize);
1910 printInfo(
"%7lld %6d %4d %7d %7d %7d %5d %4d %5.1f%% %6.1f %s:%d\n",
1911 (
long long)(chkmem->elemsize), nchunks, neagerchunks, nelems,
1912 neagerelems, chkmem->lazyfreesize, chkmem->ngarbagecalls, chkmem->ngarbagefrees,
1913 100.0 * (
double) (neagerelems + chkmem->lazyfreesize) / (
double) (nelems),
1914 (
double)chkmem->elemsize * nelems / (1024.0*1024.0),
1915 chkmem->filename, chkmem->line);
1917 printInfo(
"%7lld %6d %4d %7d %7d %7d %5.1f%% %6.1f\n",
1918 (
long long)(chkmem->elemsize), nchunks, neagerchunks, nelems,
1919 neagerelems, chkmem->lazyfreesize,
1920 100.0 * (
double) (neagerelems + chkmem->lazyfreesize) / (
double) (nelems),
1921 (
double)chkmem->elemsize * nelems / (1024.0*1024.0));
1927 printInfo(
"%7lld <unused> %5d %4d %s:%d\n",
1928 (
long long)(chkmem->elemsize), chkmem->ngarbagecalls, chkmem->ngarbagefrees,
1929 chkmem->filename, chkmem->line);
1931 printInfo(
"%7lld <unused>\n", (
long long)(chkmem->elemsize));
1935 totalnchunks += nchunks;
1936 totalneagerchunks += neagerchunks;
1937 totalnelems += nelems;
1938 totalneagerelems += neagerelems;
1939 totalnlazyelems += chkmem->lazyfreesize;
1941 totalngarbagecalls += chkmem->ngarbagecalls;
1942 totalngarbagefrees += chkmem->ngarbagefrees;
1944 chkmem = chkmem->nextchkmem;
1948 printInfo(
" Total %6d %4d %7d %7d %7d %5d %4d %5.1f%% %6.1f\n",
1949 totalnchunks, totalneagerchunks, totalnelems, totalneagerelems, totalnlazyelems,
1950 totalngarbagecalls, totalngarbagefrees,
1951 totalnelems > 0 ? 100.0 * (
double) (totalneagerelems + totalnlazyelems) / (
double) (totalnelems) : 0.0,
1952 (
double)allocedmem/(1024.0*1024.0));
1954 printInfo(
" Total %6d %4d %7d %7d %7d %5.1f%% %6.1f\n",
1955 totalnchunks, totalneagerchunks, totalnelems, totalneagerelems, totalnlazyelems,
1956 totalnelems > 0 ? 100.0 * (
double) (totalneagerelems + totalnlazyelems) / (
double) (totalnelems) : 0.0,
1957 (
double)allocedmem/(1024.0*1024.0));
1959 printInfo(
"%d blocks (%d unused), %lld bytes allocated, %lld bytes free",
1960 nblocks + nunusedblocks, nunusedblocks, allocedmem, freemem);
1961 if( allocedmem > 0 )
1962 printInfo(
" (%.1f%%)", 100.0 * (
double) freemem / (
double) allocedmem);
1972 long long allocedmem = 0;
1973 long long freemem = 0;
1977 assert(blkmem !=
NULL);
1981 chkmem = blkmem->chkmemhash[i];
1982 while( chkmem !=
NULL )
1987 int neagerelems = 0;
1989 for( c = 0; c < chkmem->nchunks; ++c )
1991 chunk = chkmem->chunks[c];
1992 assert(chunk !=
NULL);
1993 assert(chunk->elemsize == chkmem->elemsize);
1994 assert(chunk->chkmem == chkmem);
1996 nelems += chunk->storesize;
1997 if( chunk->eagerfree !=
NULL )
1998 neagerelems += chunk->eagerfreesize;
2001 assert(nchunks == chkmem->nchunks);
2002 assert(nelems == chkmem->storesize);
2003 assert(neagerelems == chkmem->eagerfreesize);
2007 allocedmem += (
long long)chkmem->elemsize * (
long long)nelems;
2008 freemem += (
long long)chkmem->elemsize * ((
long long)neagerelems + (
long long)chkmem->lazyfreesize);
2010 if( nelems != neagerelems + chkmem->lazyfreesize )
2013 printInfo(
"%lld bytes (%d elements of size %lld) not freed. First Allocator: %s:%d\n",
2014 (((
long long)nelems - (
long long)neagerelems) - (
long long)chkmem->lazyfreesize)
2015 * (
long long)(chkmem->elemsize),
2016 (nelems - neagerelems) - chkmem->lazyfreesize, (
long long)(chkmem->elemsize),
2017 chkmem->filename, chkmem->line);
2019 printInfo(
"%lld bytes (%d elements of size %lld) not freed.\n",
2020 ((nelems - neagerelems) - chkmem->lazyfreesize) * (
long long)(chkmem->elemsize),
2021 (nelems - neagerelems) - chkmem->lazyfreesize, (
long long)(chkmem->elemsize));
2025 chkmem = chkmem->nextchkmem;
2029 if( allocedmem != freemem )
2030 printInfo(
"%lld bytes not freed in total.\n", allocedmem - freemem);