summaryrefslogtreecommitdiff
path: root/libc/stdlib/malloc-standard/mallopt.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2003-12-30 10:40:49 +0000
committerEric Andersen <andersen@codepoet.org>2003-12-30 10:40:49 +0000
commit8d532c51318bad2436880ecac972c9dfa3996c9b (patch)
tree821863358734242feb99643e9d66ee9b175ad464 /libc/stdlib/malloc-standard/mallopt.c
parent4c9086ee4afde4257a4b4a8f55e05932d1b6acfd (diff)
Rework malloc. The new default implementation is based on dlmalloc from Doug
Lea. It is about 2x faster than the old malloc-930716, and behave itself much better -- it will properly release memory back to the system, and it uses a combination of brk() for small allocations and mmap() for larger allocations. -Erik
Diffstat (limited to 'libc/stdlib/malloc-standard/mallopt.c')
-rw-r--r--libc/stdlib/malloc-standard/mallopt.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/libc/stdlib/malloc-standard/mallopt.c b/libc/stdlib/malloc-standard/mallopt.c
new file mode 100644
index 000000000..e28792099
--- /dev/null
+++ b/libc/stdlib/malloc-standard/mallopt.c
@@ -0,0 +1,64 @@
+/*
+ This is a version (aka dlmalloc) of malloc/free/realloc written by
+ Doug Lea and released to the public domain. Use, modify, and
+ redistribute this code without permission or acknowledgement in any
+ way you wish. Send questions, comments, complaints, performance
+ data, etc to dl@cs.oswego.edu
+
+ VERSION 2.7.2 Sat Aug 17 09:07:30 2002 Doug Lea (dl at gee)
+
+ Note: There may be an updated version of this malloc obtainable at
+ ftp://gee.cs.oswego.edu/pub/misc/malloc.c
+ Check before installing!
+
+ Hacked up for uClibc by Erik Andersen <andersen@codepoet.org>
+*/
+
+#include "malloc.h"
+
+
+/* ------------------------------ mallopt ------------------------------ */
+int mallopt(int param_number, int value)
+{
+ int ret;
+ mstate av;
+
+ ret = 0;
+
+ LOCK;
+ av = get_malloc_state();
+ /* Ensure initialization/consolidation */
+ __malloc_consolidate(av);
+
+ switch(param_number) {
+ case M_MXFAST:
+ if (value >= 0 && value <= MAX_FAST_SIZE) {
+ set_max_fast(av, value);
+ ret = 1;
+ }
+ break;
+
+ case M_TRIM_THRESHOLD:
+ av->trim_threshold = value;
+ ret = 1;
+ break;
+
+ case M_TOP_PAD:
+ av->top_pad = value;
+ ret = 1;
+ break;
+
+ case M_MMAP_THRESHOLD:
+ av->mmap_threshold = value;
+ ret = 1;
+ break;
+
+ case M_MMAP_MAX:
+ av->n_mmaps_max = value;
+ ret = 1;
+ break;
+ }
+ UNLOCK;
+ return ret;
+}
+