Reducing array.length triggers reallocation

milentin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Dec 27 23:02:38 PST 2015


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 would 
> be no allocation.
>
> At least there are no copies and .ptr property of the array 
> does not change.
>
> [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 there was an allocation (attempt).
>
> Can someone verify that please. At least, can someone show 
> where GC.realloc() source is.
>
> Thank you,
> Ali

Thanks for the feedback, I have opened 
https://issues.dlang.org/show_bug.cgi?id=15481.


More information about the Digitalmars-d-learn mailing list