Avoid deallocate empty arrays?

Q. Schroll qs.il.paperinik at gmail.com
Thu Dec 17 16:46:47 UTC 2020


On Thursday, 17 December 2020 at 16:11:37 UTC, IGotD- wrote:
> It's common using arrays for buffering

Outside of CTFE, use an Appender.¹ Unless you're having a 
const/immutable element type, Appender can shrink and reuse 
space.² If you have, reallocation is necessary anyway not to 
break const/immutable' guarantees.

¹ https://dlang.org/phobos/std_array.html#appender
² https://dlang.org/phobos/std_array.html#.Appender.clear


More information about the Digitalmars-d-learn mailing list