summaryrefslogtreecommitdiff
path: root/libc/stdlib/malloc/realloc.c
diff options
context:
space:
mode:
authorMiles Bader <miles@lsi.nec.co.jp>2002-07-23 06:50:40 +0000
committerMiles Bader <miles@lsi.nec.co.jp>2002-07-23 06:50:40 +0000
commit83cef9f931bcd2030f42079c332525e1e73ab6aa (patch)
tree5867067ac5387998a301f69a59ca6d78b26680d5 /libc/stdlib/malloc/realloc.c
parenta9752043dd652d0fb4addf947b76e57c588f430c (diff)
* Automatically try to unmap heap free-areas when they get very big.
* Instead of using mmap/munmap directly for large allocations, just use the heap for everything (this is reasonable now that heap memory can be unmapped). * Use sbrk instead of mmap/munmap on systems with an MMU.
Diffstat (limited to 'libc/stdlib/malloc/realloc.c')
-rw-r--r--libc/stdlib/malloc/realloc.c17
1 files changed, 2 insertions, 15 deletions
diff --git a/libc/stdlib/malloc/realloc.c b/libc/stdlib/malloc/realloc.c
index f18ed9eb6..091b3392b 100644
--- a/libc/stdlib/malloc/realloc.c
+++ b/libc/stdlib/malloc/realloc.c
@@ -25,7 +25,7 @@ void *realloc (void *mem, size_t new_size)
return malloc (new_size);
else
{
- void *base_mem = (size_t *)mem - 1;
+ void *base_mem = mem - MALLOC_ALIGNMENT;
size_t size = *(size_t *)base_mem;
MALLOC_DEBUG ("realloc: 0x%lx, %d (base = 0x%lx, total_size = %d)\n",
@@ -39,20 +39,7 @@ void *realloc (void *mem, size_t new_size)
size_t ext_size = new_size - size;
void *ext_addr = (char *)base_mem + ext_size;
- if (size >= MALLOC_MMAP_THRESHOLD)
- /* Try to extend this block in place using mmap. */
- {
- ext_size += MALLOC_ROUND_UP_TO_PAGE_SIZE (ext_size);
-
- new_mem = mmap (ext_addr, ext_size, PROT_READ | PROT_WRITE,
- MAP_FIXED | MAP_SHARED | MAP_ANONYMOUS, 0, 0);
- if (new_mem == MAP_FAILED)
- /* Can't do it. */
- ext_size = 0;
- }
- else
- ext_size = __heap_alloc_at (&__malloc_heap, ext_addr, ext_size);
-
+ ext_size = __heap_alloc_at (&__malloc_heap, ext_addr, ext_size);
if (! ext_size)
/* Our attempts to extend MEM in place failed, just
allocate-and-copy. */