2 This is a version (aka dlmalloc) of malloc/free/realloc written by
3 Doug Lea and released to the public domain. Use, modify, and
4 redistribute this code without permission or acknowledgement in any
5 way you wish. Send questions, comments, complaints, performance
6 data, etc to dl@cs.oswego.edu
8 VERSION 2.7.2 Sat Aug 17 09:07:30 2002 Doug Lea (dl at gee)
10 Note: There may be an updated version of this malloc obtainable at
11 ftp://gee.cs.oswego.edu/pub/misc/malloc.c
12 Check before installing!
14 Hacked up for uClibc by Erik Andersen <andersen@codepoet.org>
19 libc_hidden_proto(fprintf)
20 libc_hidden_proto(stderr)
22 /* ------------------------------ mallinfo ------------------------------ */
23 libc_hidden_proto(mallinfo)
24 struct mallinfo mallinfo(void)
37 av = get_malloc_state();
38 /* Ensure initialization */
40 __malloc_consolidate(av);
46 avail = chunksize(av->top);
47 nblocks = 1; /* top always exists */
49 /* traverse fastbins */
53 for (i = 0; i < NFASTBINS; ++i) {
54 for (p = av->fastbins[i]; p != 0; p = p->fd) {
56 fastavail += chunksize(p);
62 /* traverse regular bins */
63 for (i = 1; i < NBINS; ++i) {
65 for (p = last(b); p != b; p = p->bk) {
67 avail += chunksize(p);
71 mi.smblks = nfastblocks;
74 mi.uordblks = av->sbrked_mem - avail;
75 mi.arena = av->sbrked_mem;
76 mi.hblks = av->n_mmaps;
77 mi.hblkhd = av->mmapped_mem;
78 mi.fsmblks = fastavail;
79 mi.keepcost = chunksize(av->top);
80 mi.usmblks = av->max_total_mem;
84 libc_hidden_def(mallinfo)
86 void malloc_stats(FILE *file)
95 fprintf(file, "total bytes allocated = %10u\n", (unsigned int)(mi.arena + mi.hblkhd));
96 fprintf(file, "total bytes in use bytes = %10u\n", (unsigned int)(mi.uordblks + mi.hblkhd));
97 fprintf(file, "total non-mmapped bytes allocated = %10d\n", mi.arena);
98 fprintf(file, "number of mmapped regions = %10d\n", mi.hblks);
99 fprintf(file, "total allocated mmap space = %10d\n", mi.hblkhd);
100 fprintf(file, "total allocated sbrk space = %10d\n", mi.uordblks);
102 fprintf(file, "number of free chunks = %10d\n", mi.ordblks);
103 fprintf(file, "number of fastbin blocks = %10d\n", mi.smblks);
104 fprintf(file, "space in freed fastbin blocks = %10d\n", mi.fsmblks);
106 fprintf(file, "maximum total allocated space = %10d\n", mi.usmblks);
107 fprintf(file, "total free space = %10d\n", mi.fordblks);
108 fprintf(file, "memory releasable via malloc_trim = %10d\n", mi.keepcost);