Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #557 (closed enhancement: fixed)

Opened 1 year ago

Last modified 1 year ago

Preserve GC block attributes across reallocations

Reported by: sean Assigned to: sean
Priority: major Milestone: 0.99.3
Component: Core Functionality Version: 0.99 RC3 Xammy
Keywords: Cc:

Description

Should also add addrOf, etc, from test code.

Change History

08/04/07 09:20:00 changed by sean

  • type changed from defect to enhancement.

08/28/07 11:41:59 changed by sean

  • status changed from new to assigned.

I just realized that this introduces an interesting problem. To reduce the number of locks required for an attribute-preserving resize operation, gc_realloc() should really be made to support resizing slices (by providing a length parameter to limit the copied data). However, this would make it impossible to use C malloc/realloc/free as a "garbage collector" for a D program, because it has undefined behavior if you ask it to realloc an interior pointer.

The best alternative I've come up with so far is to provide a general info routine and continue using two calls as now. So the process would be something like:

struct GCInfo
{
    void*      base;
    size_t     size;
    GC.BlkAttr attr;
}

GCInfo info = gc_getInfo( p );

if( size is too small )
{
    p = gc_malloc( new size, attr );
}

My only concern about this is that it seems redundant to provide aggregate information that's available individually. Also, I'm not sure how much information to provide. Size and attributes are necessary. Providing the base pointer (if known) could be handy and seems useful for completeness, but perhaps it makes the operation too expensive?

09/30/07 19:23:42 changed by kris

  • milestone changed from 1.0 to 0.99.2 RC5.

we need to get this fixed to avoid IO leaks ?

10/01/07 10:58:32 changed by sean

Yup. Unfortunately, it's a rather large task and will require quite a few changes to the compiler runtime. I'll give it a look this month.

10/04/07 14:53:09 changed by sean

Just a note. I had considered changing realloc to include a parameter specifying an upper bound of data to preserve. The idea being that realloc could then be used to resize pointers to the middle of a memory block. However, I've decided against this because it is not possible to replicate this functionality using C realloc, and I'd like to continue supporting the C allocators as a possible GC alternative. So the method described above will be used instead.

10/04/07 15:36:28 changed by sean

  • milestone changed from 0.99.2 RC5 to 0.99.3 RC6.

10/12/07 16:00:09 changed by sean

The addrOf routine has been added in changeset [2647].

10/12/07 16:54:54 changed by sean

The query routine has been added in changeset [2648].

10/13/07 11:42:13 changed by sean

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

Closed by changeset [2649].