Arena0: system bytes = 2625536 in use bytes = 1063008 Arena1: system bytes = 2011136 in use bytes = 314864 Arena2: system bytes = 2318336 in use bytes = 879032 Arena3: system bytes = 2527232 in use bytes = 475776 Total (incl. mmap): system bytes = 9482240 in use bytes = 2732680 max mmap regions = 13 max mmap bytes = 5701632
system bytes表明向系统申请的,in use bytes表明使用中的。 从Total来看,还有6.7MB内存空闲着。
(2)使用mallinfo函数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
voiddisplay_mallinfo(void) { structmallinfomi; mi = mallinfo(); printf("Total non-mmapped bytes (arena): %d\n", mi.arena); printf("# of free chunks (ordblks): %d\n", mi.ordblks); printf("# of free fastbin blocks (smblks): %d\n", mi.smblks); printf("# of mapped regions (hblks): %d\n", mi.hblks); printf("Bytes in mapped regions (hblkhd): %d\n", mi.hblkhd); printf("Max. total allocated space (usmblks): %d\n", mi.usmblks); printf("Free bytes held in fastbins (fsmblks): %d\n", mi.fsmblks); printf("Total allocated space (uordblks): %d\n", mi.uordblks); printf("Total free space (fordblks): %d\n", mi.fordblks); printf("Topmost releasable block (keepcost): %d\n", mi.keepcost); }
打印如下:
1 2 3 4 5 6 7 8 9 10
Total non-mmapped bytes (arena):9482240 # of free chunks (ordblks): 1072 # of free fastbin blocks (smblks): 37 # of mapped regions (hblks): 0 Bytes in mapped regions (hblkhd):0 Max. total allocated space (usmblks):0 Free bytes held in fastbins (fsmblks):1504 Total allocated space (uordblks):2732680 Total free space (fordblks):6749560 Topmost releasable block (keepcost):96936