avoiding loops, allocation using arrays and ranges

Mithun Hunsur via Digitalmars-d digitalmars-d at puremagic.com
Mon Mar 28 02:01:08 PDT 2016


On Monday, 28 March 2016 at 08:21:33 UTC, Basile B. wrote:
> 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*/}

I believe you're able to use 
https://dlang.org/phobos/std_algorithm_mutation.html#.copy to 
achieve this.


More information about the Digitalmars-d mailing list