avoiding loops, allocation using arrays and ranges

Basile B. via Digitalmars-d digitalmars-d at puremagic.com
Mon Mar 28 01:21:33 PDT 2016


On Monday, 28 March 2016 at 08:13:08 UTC, Danni Coy wrote:
>>     writeln(v.array); // everything gets eval by .array
>
> .array allocates a new array. I want to store the result of v 
> in a
> buffer that I have preallocated
> in my case this just happens to be a[];
>
> This is quite important.
> This is also the step I would like a more elegant way to deal 
> with.

.array is just used to render the result in this demo. It doesn't 
need to be used at all. Anyway the result can be yielded in a 
pre-allocated array without problem, at the end of the functional 
stuff just loop on the resulting range and copy.
With UFCS this can do something like:

     foreach(s; a.process!(xfade)(b, 4).process!(xfade)(b, 4))
     {/*copy each sample to pre alloc array*/}





More information about the Digitalmars-d mailing list