www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Best way to clear dynamic array for reuse

reply Michael Rynn <michaelrynn optusnet.com.au> writes:
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
Dec 28 2016
parent Nemanja Boric <4burgos gmail.com> writes:
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
Dec 28 2016