Re: Is GC smart enough not to reallocate?

2016-06-16 Thread John Colvin via Digitalmars-d
On Thursday, 16 June 2016 at 13:54:11 UTC, MMJones wrote: Suppose one has something like class foo { int[] x; void bar() { x = []; } } Does the GC trash the "cache" when calling bar or does it realize that it can use the same memory for x and essentially just shortens the

Is GC smart enough not to reallocate?

2016-06-16 Thread MMJones via Digitalmars-d
Suppose one has something like class foo { int[] x; void bar() { x = []; } } Does the GC trash the "cache" when calling bar or does it realize that it can use the same memory for x and essentially just shortens the array? Is it equivalent to setting length = 0? I'm a bit

Re: Is GC smart enough not to reallocate?

2016-06-16 Thread Steven Schveighoffer via Digitalmars-d
On 6/16/16 9:54 AM, MMJones wrote: Suppose one has something like class foo { int[] x; void bar() { x = []; } } Does the GC trash the "cache" when calling bar or does it realize that it can use the same memory for x and essentially just shortens the array? If you reassign