Best way to clear dynamic array for reuse

Nemanja Boric via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Dec 28 06:35:05 PST 2016


On Wednesday, 28 December 2016 at 12:30:33 UTC, Michael Rynn 
wrote:
>
> It takes a bit of work to get around the mutable buffers 
> problem in D language arrays. I found it made a performance 
> difference in xml parsing.
>
>
> https://github.com/betrixed/dlang-xml/blob/master/xml/util/buffer.d
>
> /**
> 	Buffer(T) - Versatile appendable D array for buffer reuse,
> append, reset with preserved capacity.
> 	Has additional template specializations for char, wchar, dchar,
> which always has an extra space for appending a terminating null
> character.
> 	Magic property is no memory reallocation or capacity loss if
> length set to zero.
> 	Resulting speed ups from reduced memory manager work. Perhaps
> reduction in hardware cache misses.
> 	Almost a drop in replacement for T[]. Some features adopted 
> from
> std.array and std.range
> */

See also: 
https://github.com/sociomantic-tsunami/ocean/blob/v2.x.x/src/ocean/core/Buffer.d


More information about the Digitalmars-d-learn mailing list