alloca is slow and dangerous
Ola Fosheim Grostad
ola.fosheim.grostad at gmail.com
Fri Jan 1 18:49:03 UTC 2021
On Friday, 1 January 2021 at 17:55:33 UTC, Steven Schveighoffer
wrote:
> In my experience, using it isn't extremely beneficial -- since
> it's in stdc, it requires the c library, which means you have
> malloc/free, which is much safer/usable.
I never use alloca directly, but in C you can just use an int
variable for the dynamic array size. I find that useful for
things like building a zero terminated path that only will be
used with one function call. Or for a FFT buffer that is only
known at runtime and I want to use hot memory (already in cache).
To do that fixed size would take maybe 200 KB, could easily be
100 times more than needed... And the next stack frame would be
cold as hell...
More information about the Digitalmars-d
mailing list