Reducing array.length triggers reallocation

2015-12-27 Thread milentin via Digitalmars-d-learn
I've just started learning D and noticed a bug, but wanted to confirm it here before reporting it. According to spec: "If the new array length is shorter, the array is not reallocated, and no data is copied. It is equivalent to slicing the array". Contradicted by a trivial program: void

Re: Reducing array.length triggers reallocation

2015-12-27 Thread Ali Çehreli via Digitalmars-d-learn
On 12/27/2015 02:09 AM, milentin wrote: > I've just started learning D and noticed a bug, but wanted to confirm it > here before reporting it. > > According to spec: "If the new array length is shorter, the array is not > reallocated, and no data is copied. It is equivalent to slicing the >

Re: Reducing array.length triggers reallocation

2015-12-27 Thread Ivan Kazmenko via Digitalmars-d-learn
On Sunday, 27 December 2015 at 22:36:32 UTC, Ali Çehreli wrote: [Several hours later...] You know what... I bet there is no actual allocation at all. I think what happens is, the code calls GC.realloc(24) and realloc() does not do anything. However, it still reports to the profiler that

Re: Reducing array.length triggers reallocation

2015-12-27 Thread milentin via Digitalmars-d-learn
On Sunday, 27 December 2015 at 22:36:32 UTC, Ali Çehreli wrote: I don't understand why that happens. I found one related bug: https://issues.dlang.org/show_bug.cgi?id=13750 I can understand that assignment to arr.length cannot be @nogc but I would expect a check against length so that there