alloca is slow and dangerous

welkam wwwelkam at gmail.com
Sun Jan 3 20:59:00 UTC 2021


On Sunday, 3 January 2021 at 19:33:10 UTC, IGotD- wrote:
> I think the default initialization in D is an excellent feature.
Agree. Also Walter put an escape hatch because he knew that some 
times you dont want it for performance reasons.

> MS has already stated that they want to do this in C++.
Not only MS but also linux people want default initialize 
everything so they both put effort in compilers to improve 
optimizations so they dont pay performance penalty where they 
should not. And in the end we benefit too.

> My point was that more that you will allocate exactly the 
> elements you need on the stack. For example you have have a 
> maximum of 1024 elements but usually you only use one or two 
> elements. Then static allocation of 1024 elements become crazy 
> big and also it generate more cache misses.
If that's the case then you do like Walter showed. Common case on 
the stack and uncommon big allocations on heap.

> I'm not sure why the stack allocation needs to be so enormously 
> complicated like the seminar. In general you just need to 
> subtract the stack pointer.
I'm not following you



More information about the Digitalmars-d mailing list