56 ms·
alloca isn't so bad if you have stack guards, which Microsoft has used extensively for a long time [1]. Historically Unix has lagged behind here, however, and s
by pcwalton 11y ago
alloca isn't so bad if you have stack guards, which Microsoft has used extensively for a long time [1]. Historically Unix has lagged behind here, however, and so alloca is a security risk on Unix, which leads to the "alloca is evil" advice.
There is also the fact that you permanently lose one register in your function (ebp) if you use alloca(). This is important on 32-bit x86 but is rarely discussed.
There is essentially no implementation difference between VLAs and alloca().
[1]: https://msdn.microsoft.com/en-us/library/wb1s57t5.aspx https://msdn.microsoft.com/en-us/library/wb1s57t5.aspx
- tptacek 11y agoNo, I think alloca was considered evil before Elias wrote "Smashing The Stack". I bet if you go track down the 'alloca' man page from FreeBSD 2.0, you'll find that it's use was "discouraged" even back then.
- pcwalton 11y agoYeah, you're right: https://www.freebsd.org/cgi/man.cgi?query=alloca&apropos=0&sektion=0&manpath=4.3BSD+NET%2F2&arch=default&format=html https://www.freebsd.org/cgi/man.cgi?query=alloca&apropos=0&s... The "machine dependent" reason is out of date though.