One-line change for malloc to save address space
Wolfram Gloger
wmglo@dent.med.uni-muenchen.de
Wed Feb 14 14:56:00 GMT 2001
Hi,
Here is a small change for malloc that should help save address space
when allocating beyond the sbrk() limit.
Regards,
Wolfram.
2001-02-14 Wolfram Gloger <wg@malloc.de>
* malloc/malloc.c (new_heap): When allocating large chunk aligned
to HEAP_MAX_SIZE, prefer one with lower address, to avoid `holes'
between the heaps.
Index: libc/malloc/malloc.c
===================================================================
RCS file: /cvs/glibc/libc/malloc/malloc.c,v
retrieving revision 1.78
diff -u -r1.78 malloc.c
--- malloc.c 2001/01/21 21:29:17 1.78
+++ malloc.c 2001/02/14 22:55:44
@@ -2026,7 +2026,7 @@
anyway). */
p1 = (char *)MMAP(0, HEAP_MAX_SIZE<<1, PROT_NONE, MAP_PRIVATE|MAP_NORESERVE);
if(p1 != MAP_FAILED) {
- p2 = (char *)(((unsigned long)p1 + HEAP_MAX_SIZE) & ~(HEAP_MAX_SIZE-1));
+ p2 = (char *)(((unsigned long)p1 + (HEAP_MAX_SIZE-1)) & ~(HEAP_MAX_SIZE-1));
ul = p2 - p1;
munmap(p1, ul);
munmap(p2 + HEAP_MAX_SIZE, HEAP_MAX_SIZE - ul);
More information about the Libc-hacker
mailing list