GC and slices

Oskar Linde oskar.lindeREM at OVEgmail.com
Thu Sep 14 07:35:11 PDT 2006


This is a very short question regarding the liberties of the GC. Is it 
safe to rely on data outside a slice?

For example, given:

int* a = new int[100_000] + 50_000;
std.gc.fullCollect();

I'd still assume both a[-50_000] and a[49_999] to remain valid.

But does the same hold for slices?

int[] a = (new int[100_000])[50_000..50_010];
std.gc.fullCollect();

Is the memory outside the slice 'a' still guaranteed to be valid, or is 
a compacting GC allowed to remove the unreferenced areas outside the slice?

/Oskar



More information about the Digitalmars-d mailing list