On Thu, 05 Jun 2014 15:34:13 -0400, monarch_dodra <[email protected]> wrote:

On Thursday, 5 June 2014 at 19:27:56 UTC, Steven Schveighoffer wrote:
On Thu, 05 Jun 2014 14:47:54 -0400, deadalnix
T[] arr = [ ... ];
arr = arr[$ .. $];
auto garbage = *(arr.ptr);

Believe it or not, this is actually safe.

What do you mean by "is actually safe" ? In the "can you actually believe this obviously wrong code is marked as safe" or "this code that looks wrong is actually perfectly safe"?

It's safe because of the implementation of arrays. There is always one sentinel byte that cannot be used for the block of data. This is why when you allocate e.g. 8 ints, it goes into a 32-byte block.

AFAIK, it's only safe if arr is GC allocated to a bloc smaller than a page, so the conditions are implementation defined behavior, and so is the result.

No, pages also have a sentinel byte.

-Steve

Reply via email to