Partial arrays reclaimed?
ag0aep6g via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Jan 29 14:06:56 PST 2017
On Friday, 27 January 2017 at 23:22:17 UTC, Nick Sabalausky wrote:
> Suppose an array is being used like a FIFO:
>
> -----------------------
> T[] slice;
>
> // Add:
> slice ~= T();
>
> // Remove:
> slice = slice[1..$];
> -----------------------
>
> Assuming of course there's no other references to the memory,
> as this gets used, does the any of the memory from the removed
> elements ever get GC'd?
If the array has no additional capacity, then appending will
relocate the data. I.e., copy it to a larger allocation. The old
data can then be collected. Since the old first element is not
part of the new array, it's doesn't get copied over. So the
allocation doesn't grow indefinitely.
> Also, if this is a long-running process, isn't there a
> potential danger in the array just marching through the address
> space and running out of room? (ie either running out of of
> continuous space, or hitting 0xFFF....)
If you append and pop the front over and over, the program should
reuse old locations, cycling through them.
More information about the Digitalmars-d-learn
mailing list