Minor patch. Our mem_allocate currently allocates too much memory. It
rounds up to the next 16 bytes if we are currently in the middle, but if
we are on a 16 byte boundary, it rounds up to the next 16 bytes.

This patch removes those extra 16 bytes of allocation, and simplifies our
copy_size logic during collection.

This will break Peter's COW patch. But I believe this is okay. If COW
requires a memory/buffer footer, we should explicitly code for extra bytes
in an allocation, instead of relying on the round-up behavior to work
semi-improperly.

If Peter doesn't beat me to it, I'll probably get time to make COW work
with this patch in a few weeks. I'm just trying to clean out my current
set of parrot patches before they all become out of date. :)

Mike Lambert

PS: Hopefully the line breaks come out okay in this patch. Otherwise,
I'll re-send as an attachment.

Index: resources.c
===================================================================
RCS file: /cvs/public/parrot/resources.c,v
retrieving revision 1.48
diff -u -r1.48 resources.c
--- resources.c 27 Apr 2002 19:31:08 -0000 1.48
+++ resources.c 28 Apr 2002 17:37:18 -0000
@@ -753,10 +753,7 @@
          interpreter->arena_base->string_header_pool->pool_buffer.buflen);
   interpreter->arena_base->string_header_pool->pool_buffer.bufstart = cur_spot;
   cur_size = interpreter->arena_base->string_header_pool->pool_buffer.buflen;
-  if (cur_size & 0x0f) {
-    cur_size &= ~0x0f;
-    cur_size += 16;
-  }
+  cur_size = (cur_size + 0x0f) & ~0x0f;
   cur_spot += cur_size;

   /* Collect the PMC header pool */
@@ -765,10 +762,7 @@
          interpreter->arena_base->pmc_pool->pool_buffer.buflen);
   interpreter->arena_base->pmc_pool->pool_buffer.bufstart = cur_spot;
   cur_size = interpreter->arena_base->pmc_pool->pool_buffer.buflen;
-  if (cur_size & 0x0f) {
-    cur_size &= ~0x0f;
-    cur_size += 16;
-  }
+  cur_size = (cur_size + 0x0f) & ~0x0f;
   cur_spot += cur_size;

   /* And the buffer header pool */
@@ -777,10 +771,7 @@
          interpreter->arena_base->buffer_header_pool->pool_buffer.buflen);
   interpreter->arena_base->buffer_header_pool->pool_buffer.bufstart = cur_spot;
   cur_size = interpreter->arena_base->buffer_header_pool->pool_buffer.buflen;
-  if (cur_size & 0x0f) {
-    cur_size &= ~0x0f;
-    cur_size += 16;
-  }
+  cur_size = (cur_size + 0x0f) & ~0x0f;
   cur_spot += cur_size;

   /* Run through all the STRING header pools and copy */
@@ -799,10 +790,7 @@
                string_array[i].buflen);
         string_array[i].bufstart = cur_spot;
         cur_size = string_array[i].buflen;
-        if (cur_size & 0x0f) {
-          cur_size &= ~0x0f;
-          cur_size += 16;
-        }
+        cur_size = (cur_size + 0x0f) & ~0x0f;
         cur_spot += cur_size;
       }
     }
@@ -823,10 +811,7 @@
                buffer_array[i].buflen);
         buffer_array[i].bufstart = cur_spot;
         cur_size = buffer_array[i].buflen;
-        if (cur_size & 0x0f) {
-          cur_size &= ~0x0f;
-          cur_size += 16;
-        }
+        cur_size = (cur_size + 0x0f) & ~0x0f;
         cur_spot += cur_size;
       }
     }
@@ -1007,8 +992,7 @@
 #endif

   /* Make sure we round up to a multiple of 16 */
-  size += 16;
-  size &= ~0x0f;
+  size = (size + 0x0f) & ~0x0f;
   /* Do we have enough in our top pool? */
   if (interpreter->arena_base->memory_pool->free >= size) {
     return_val = interpreter->arena_base->memory_pool->top;



Reply via email to