[uClibc-cvs] CVS uClibc/libc/stdlib/malloc-standard

CVS User andersen andersen at codepoet.org
Mon Nov 8 03:34:44 UTC 2004


Update of /var/cvs/uClibc/libc/stdlib/malloc-standard
In directory nail:/tmp/cvs-serv25017/libc/stdlib/malloc-standard

Modified Files:
	free.c mallinfo.c 
Log Message:
Some requested additional malloc entry points


--- /var/cvs/uClibc/libc/stdlib/malloc-standard/free.c	2003/12/30 10:40:49	1.1
+++ /var/cvs/uClibc/libc/stdlib/malloc-standard/free.c	2004/11/08 03:34:44	1.2
@@ -17,6 +17,37 @@
 #include "malloc.h"
 
 
+/* ------------------------- malloc_trim -------------------------
+  malloc_trim(size_t pad);
+
+  If possible, gives memory back to the system (via negative
+  arguments to sbrk) if there is unused memory at the `high' end of
+  the malloc pool. You can call this after freeing large blocks of
+  memory to potentially reduce the system-level memory requirements
+  of a program. However, it cannot guarantee to reduce memory. Under
+  some allocation patterns, some large free blocks of memory will be
+  locked between two used chunks, so they cannot be given back to
+  the system.
+  
+  The `pad' argument to malloc_trim represents the amount of free
+  trailing space to leave untrimmed. If this argument is zero,
+  only the minimum amount of memory to maintain internal data
+  structures will be left (one page or less). Non-zero arguments
+  can be supplied to maintain enough trailing space to service
+  future expected allocations without having to re-obtain memory
+  from the system.
+  
+  Malloc_trim returns 1 if it actually released any memory, else 0.
+  On systems that do not support "negative sbrks", it will always
+  return 0.
+*/
+int malloc_trim(size_t pad)
+{
+  mstate av = get_malloc_state();
+  __malloc_consolidate(av);
+  return __malloc_trim(pad, av);
+}
+
 /* ------------------------- __malloc_trim -------------------------
    __malloc_trim is an inverse of sorts to __malloc_alloc.  It gives memory
    back to the system (via negative arguments to sbrk) if there is unused
--- /var/cvs/uClibc/libc/stdlib/malloc-standard/mallinfo.c	2003/12/30 10:40:49	1.1
+++ /var/cvs/uClibc/libc/stdlib/malloc-standard/mallinfo.c	2004/11/08 03:34:44	1.2
@@ -79,3 +79,28 @@
     return mi;
 }
 
+void malloc_stats(FILE *file)
+{
+    struct mallinfo mi;
+
+    if (file==NULL) {
+	file = stderr;
+    }
+
+    mi = mallinfo();
+    fprintf(file, "total bytes allocated             = %10lu\n", (unsigned int)(mi.arena + mi.hblkhd));
+    fprintf(file, "total bytes in use bytes          = %10lu\n", (unsigned int)(mi.uordblks + mi.hblkhd));
+    fprintf(file, "total non-mmapped bytes allocated = %10lu\n", (unsigned int)(mi.arena));
+    fprintf(file, "number of mmapped regions         = %10lu\n", (unsigned int)(mi.hblks));
+    fprintf(file, "total allocated mmap space        = %10lu\n", (unsigned int)(mi.hblkhd));
+    fprintf(file, "total allocated sbrk space        = %10lu\n", (unsigned int)(mi.uordblks));
+#if 0
+    fprintf(file, "number of free chunks             = %10lu\n", (unsigned int)(mi.ordblks));
+    fprintf(file, "number of fastbin blocks          = %10lu\n", (unsigned int)(mi.smblks));
+    fprintf(file, "space in freed fastbin blocks     = %10lu\n", (unsigned int)(mi.fsmblks));
+#endif
+    fprintf(file, "maximum total allocated space     = %10lu\n", (unsigned int)(mi.usmblks));
+    fprintf(file, "total free space                  = %10lu\n", (unsigned int)(mi.fordblks));
+    fprintf(file, "memory releasable via malloc_trim = %10lu\n", (unsigned int)(mi.keepcost));
+}
+



More information about the uClibc-cvs mailing list