Change representation of dynamic arrays?
Oskar Linde
oskar.lindeREM at OVEgmail.com
Fri Oct 19 23:49:01 PDT 2007
Janice Caron wrote:
> I had always assumed that, from the start, you designed it as { ptr,
> length } deliberately in order to help the garbage collector.
>
> If you change it, then you will be maintaining a pointer (the end
> pointer) to something beyond the end of the array. For example,
> suppose I do:
>
> int[] s = new int[4];
> int[] t = new int[1000];
>
> now t.begin might end up being equal to s.end.
All array allocations in D allocate an extra byte just to prevent this.
But now when we do
>
> t = null;
>
> or t goes out of scope or we otherwise assign t, suddenly that array
> can no longer be freed, because the end pointer of s points to it.
--
Oskar
More information about the Digitalmars-d
mailing list