[En-Nut-Discussion] Use of alloca in Nut/OS
Ole Reinhardt
ole.reinhardt at embedded-it.de
Fri Aug 8 18:38:32 CEST 2008
Hi Henrik,
> 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.
We just differentiate between GNU and IMAGECRAFT in the usage of alloca.
Imagefcraft does not support alloca as well.
> 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.
That's right. My intention was to speedup the code by using alloca for
dynamic allocation of just small amounts of stack for temporaly holding
a short string. Using NutHeapAlloc is much slower and will potentially
fragment the heap if some other heap is allocated in the meanwhile.
> 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__) &&
> defined(__arm__) "
Would be an idea. I even would vote to use it in more places, but that's
only possible if every compiler would support alloca. Perhaps we could
add our own alloca implementation? (By just moving the stack pointer by
x bytes). Shure, it does not help on systems with low memory...
> Any thoughts on this?
Any more thoughts on it?
Ole Reinhardt
--
_____________________________________________________________
| |
| Embedded-IT Hard- und Softwarelösungen |
| |
| Ole Reinhardt Tel. / Fax: +49 (0)271 7420433 |
| Luisenstraße 29 Mobil: +49 (0)177 7420433 |
| 57076 Siegen eMail: ole.reinhardt at embedded-it.de |
| Germany Web: http://www.embedded-it.de |
| UstID / VAT: DE198944716 |
|_____________________________________________________________|
More information about the En-Nut-Discussion
mailing list