Best way to clear dynamic array for reuse

Michael Rynn via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Dec 28 04:30:33 PST 2016


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
*/


-- 
Technosphere-brain-shrink - trying to give it up


More information about the Digitalmars-d-learn mailing list