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>
18 #include <stdio.h> /* fprintf */
21 /* ------------------------------ mallinfo ------------------------------ */
22 struct mallinfo mallinfo(void)
35 av = get_malloc_state();
36 /* Ensure initialization */
38 __malloc_consolidate(av);
44 avail = chunksize(av->top);
45 nblocks = 1; /* top always exists */
47 /* traverse fastbins */
51 for (i = 0; i < NFASTBINS; ++i) {
52 for (p = av->fastbins[i]; p != 0; p = p->fd) {
54 fastavail += chunksize(p);
60 /* traverse regular bins */
61 for (i = 1; i < NBINS; ++i) {
63 for (p = last(b); p != b; p = p->bk) {
65 avail += chunksize(p);
69 mi.smblks = nfastblocks;
72 mi.uordblks = av->sbrked_mem - avail;
73 mi.arena = av->sbrked_mem;
74 mi.hblks = av->n_mmaps;
75 mi.hblkhd = av->mmapped_mem;
76 mi.fsmblks = fastavail;
77 mi.keepcost = chunksize(av->top);
78 mi.usmblks = av->max_total_mem;
82 libc_hidden_def(mallinfo)
84 void malloc_stats(FILE *file)
94 "total bytes allocated = %10u\n"
95 "total bytes in use bytes = %10u\n"
96 "total non-mmapped bytes allocated = %10d\n"
97 "number of mmapped regions = %10d\n"
98 "total allocated mmap space = %10d\n"
99 "total allocated sbrk space = %10d\n"
101 "number of free chunks = %10d\n"
102 "number of fastbin blocks = %10d\n"
103 "space in freed fastbin blocks = %10d\n"
105 "maximum total allocated space = %10d\n"
106 "total free space = %10d\n"
107 "memory releasable via malloc_trim = %10d\n",
109 (unsigned int)(mi.arena + mi.hblkhd),
110 (unsigned int)(mi.uordblks + mi.hblkhd),