August 03Re: dynamic array .length vs .reserve - what's the difference?
Posted in reply to Steven Schveighoffer
On Saturday, 1 August 2020 at 16:04:01 UTC, Steven Schveighoffer wrote: > On 7/31/20 12:32 PM, wjoe wrote: >> On Friday, 31 July 2020 at 04:28:57 UTC, Ali Çehreli wrote: >>> Another option, which is curiously said to be more performant in memory allocation than native arrays, is std.array.Appender. I've used function-local static Appenders to cut down on memory allocation. Here is an uncompiled pseudo code: >>> >>> [...] >> >> This looks like an even better way to do it. >> >> Thanks, Ali :) > > Just FYI, the reason this is faster is because there is no need to go through the opaque calls into druntime to figure out if appending-in-place is possible. The reserved length is stored directly in the struct. > > -Steve That's good to know, thanks :) By the looks of it, Appender is half duplicating the runtime :)
Copyright © 1999-2018 by the D Language Foundation