[En-Nut-Discussion] Use of alloca in Nut/OS
hmlists at focus-sw.com
Fri Aug 8 10:03:32 CEST 2008
I just tried to compile Nut/OS 4.6.0 stable with my old WinAVR-20060421
which uses avr-gcc 3.4.6. Compilation fails because this older avrlibc
version does not support alloca(). Of course an upgrade to latest WinAVR
would fix this, however above version compiles very compact code compared to
avr-gcc 4.3.0: 10% saving in code space. So a good reason to use it.
This incident brought my attention to alloca and I am wondering if the main
code of Nut/OS should use alloca at all?
Alloca is used in two modules ssi.c and cgi.c.
On systems with larger amounts of memory alloca would be a good option for
dynamic memory. However on the AVR stack space is very limited and often
only a few hundred bytes per thread. Allocating larger strings on the stack
can easily cause stack overflow.
The other issue which arises is that Imagecraft does not support it either.
I suggest to use it only for the ARM/gcc combination and guard it's use with
conditional compilation of the form "#if defined(__GNUC__) &&
Any thoughts on this?
More information about the En-Nut-Discussion