On Tue, 18 Sep 2012 08:02:29 -0400, Don Clugston <[email protected]> wrote:

On 17/09/12 18:40, bearophile wrote:
monarch_dodra:

IMO, this should really be built-in, in particular, since, in my
understanding, an array is internally represented by the ptr and
ptrEnd pair anyways.

Currently this is not true, take a look at the ABI part in the D site.
Currently it's a pointer and length. Walter and/or Andrei discussed the
idea of turning them into two pointers, but I don't know if and why that
change was refused.

Because it would be a mistake. You can efficiently get from (ptr, length) to (ptr, endPtr) but the reverse is not true.

There is another reason to avoid this.

Note that if I have two consecutive blocks of memory:

0...4
and
4...8

If we define an array that points to the first block as a pointer to 0 and a pointer to 4, then that array also effectively points at the second block (4...8). The way the GC works, it will not release the second block as long as you have a pointer to the first, even though the second pointer is not technically pointing at the block.

-Steve

Reply via email to