Ticket #15 (closed defect: fixed)

Opened 3 years ago

Last modified 10 months ago

Tuning HeapSlice

Reported by: sean Assigned to:
Priority: minor Milestone:
Component: Other Version:
Keywords: Cc:

Description

If expand() causes a reallocation then the entire array will be available, not just the area above used. It might be best to do something like this to ensure optimal use of available storage:

void* expand (uint size)
{
    if ((used + size) > buffer.length)
    {
       void* old = buffer.ptr;
       buffer.length = (used + size) * 2;
       if (buffer.ptr != old)
          used = 0;
    }
    return &buffer [used];
}

Change History

04/06/06 03:45:30 changed by kris

As I understand it, resizing an array is the same as a realloc? In the expand() method, existing data is expected to be copied over into the new space. I certainly hope that's correct!

12/07/07 02:42:30 changed by kris

  • status changed from new to closed.
  • resolution set to fixed.