dynamic array .length vs .reserve - what's the difference?

Steven Schveighoffer schveiguy at gmail.com
Sat Aug 1 16:04:01 UTC 2020


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


More information about the Digitalmars-d-learn mailing list