summaryrefslogtreecommitdiff
path: root/src/ralloc.c
diff options
context:
space:
mode:
authorJim Blandy <jimb@redhat.com>1992-09-09 00:05:42 +0000
committerJim Blandy <jimb@redhat.com>1992-09-09 00:05:42 +0000
commit16a5c72935c9b945d083e6e7397033182ece3357 (patch)
tree71df8225634f0a71f7cf02f3d09c74dc40073394 /src/ralloc.c
parent6cf420725b8c77321b37c858f7b698bd76224851 (diff)
downloademacs-16a5c72935c9b945d083e6e7397033182ece3357.tar.gz
* ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
end of the heap, copying the data to it, and then freeing the original bloc, just expand the original block. This saves a copy and a call to sbrk, and also removes the large spike in memory allocation that would occur when resizing large buffers. And it's less code.
Diffstat (limited to 'src/ralloc.c')
-rw-r--r--src/ralloc.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/ralloc.c b/src/ralloc.c
index d06472f8ea9..fb8325c04de 100644
--- a/src/ralloc.c
+++ b/src/ralloc.c
@@ -376,10 +376,10 @@ r_alloc_free (ptr)
free_bloc (dead_bloc);
}
-/* Given a pointer at address PTR to relocatable data, resize it
- to SIZE. This is done by obtaining a new block and freeing the
- old, unless SIZE is less than or equal to the current bloc size,
- in which case nothing happens and the current value is returned.
+/* Given a pointer at address PTR to relocatable data, resize it to SIZE.
+ This is done by shifting all blocks above this one up in memory,
+ unless SIZE is less than or equal to the current bloc size, in
+ which case nothing happens and the current value is returned.
The contents of PTR is changed to reflect the new bloc, and this
value is returned. */
@@ -389,22 +389,24 @@ r_re_alloc (ptr, size)
POINTER *ptr;
SIZE size;
{
- register bloc_ptr old_bloc, new_bloc;
+ register bloc_ptr bloc;
- old_bloc = find_bloc (ptr);
- if (old_bloc == NIL_BLOC)
+ bloc = find_bloc (ptr);
+ if (bloc == NIL_BLOC)
abort ();
- if (size <= old_bloc->size)
+ if (size <= bloc->size)
/* Wouldn't it be useful to actually resize the bloc here? */
return *ptr;
- new_bloc = get_bloc (size);
- new_bloc->variable = ptr;
- safe_bcopy (old_bloc->data, new_bloc->data, old_bloc->size);
- *ptr = new_bloc->data;
+ obtain (size - bloc->size);
+ relocate_some_blocs (bloc->next, bloc->data + size);
- free_bloc (old_bloc);
+ /* Zero out the new space in the bloc, to help catch bugs faster. */
+ bzero (bloc->data + bloc->size, size - bloc->size);
+
+ /* Indicate that this block has a new size. */
+ bloc->size = size;
return *ptr;
}