alloca is slow and dangerous

welkam wwwelkam at gmail.com
Sun Jan 3 19:12:47 UTC 2021


Im going to respond to both messages

On Friday, 1 January 2021 at 15:19:07 UTC, IGotD- wrote:
> Why is it hard to implement?

Because it requires backend help. alloca is a special function

On Friday, 1 January 2021 at 17:48:22 UTC, Patrick Schluter wrote:
> On Friday, 1 January 2021 at 15:19:07 UTC, IGotD- wrote:
>> In D static arrays have an additional problem and that is that 
>> D will initialize the array by default. For stability this is 
>> great but performance this takes more time. VLA can be a 
>> better option here as you initialize exactly the amount 
>> elements you need.
>
> yes

Usually this forum has excellent technical responses but this 
time you dropped ball on this one. Behold

byte[128] = void;

Walter did a talk on this one.
DConf 2019 Day 1 Keynote: Allocating Memory with the D 
Programming Language -- Walter Bright
https://www.youtube.com/watch?t=2210&v=_PB6Hdi4R7M

On Friday, 1 January 2021 at 15:19:07 UTC, IGotD- wrote:
>> 3. slower than static array on the stack
>
> The reason was strangely a lot of code for just allocating on 
> the stack. He said he wasn't even using -O2 optimization and 
> with -O2 it would be smaller. In general it shouldn't be that 
> bad.

Later he said that when people replaced VLA in kernel they found 
13% speed up. While it was not stated kernel should be 
benchmarked with optimizations enabled.



More information about the Digitalmars-d mailing list