snazzy-d/sdc

Support appendable allocations

deadalnix opened this issue · 3 comments

D's GC support appendable allocations. An appendable allocation store the size that is actually allocated in its metadata, so that it knows if a reallocation is necessary when appending.

The allocated size can be stored as follow:

  1. In a slab, at the end of the entry, as 1 byte if the size of an entry is <= 256 and 2 bytes for larger allocations.
  2. For large allocations, in the Extent, as slabData are not useful.
    Bitmap!512 _slabData = void;

When resizing appendable allocations, the size needs to be rounded up to the next size class (this is important for large allocations, to ensure reallocation are O(1) amortized instead of O(n) ).

For small allocation, appendable allocation may need another set of bins, or split slabData in 2, which will excludes bin sizes which contains more than 256 elements.

The API of the GC needs to be extended with a method that allows us to query the size stored via the appendable mechanism.

This task require a bit of an explanation on the goals. D supports slices that can be appended to. For instance:

int[] a = [1, 2, 3];
a ~= 4;
assert(a == [1, 2, 3, 4]);

For performances reasons, it is desirable to only reallocate when it is actually needed. For this to be possible, the GC needs to be able to maintain information about the bytes that are actually used in an allocation and provide way to extent an allocation in place on a best effort basis.

We do not necessarily desire to have the whole feature implemented in this task, as there is likely going to be extensive runtime support required, a lot of it falls outside of the scope of the GC (for instance, if a reallocation needs to take place, and the element of the array have copy constructors, these constructors need to run).

Resolved by #303

This is solved, should be closed