[En-Nut-Discussion] Use of alloca in Nut/OS

Harald Kipp harald.kipp at egnite.de
Mon Aug 11 11:18:37 CEST 2008


Ole Reinhardt wrote:
> 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.

I still _believe_, that the Imagecraft version will run faster and 
produce less code with both compilers. It avoids additional memory 
allocation. The reasons for not replacing the initial code are, that I 
had no chance to extensively test it, specifically on an ARM target and 
that I hadn't been able yet to provide a proof, that my assumption about 
speed and size is correct.

More generally speaking, however, I fully agree, that using alloca 
instead of malloc will make sense in many routines. Note that, Nut/OS 
will less likely suffer from heap fragmentations, because it uses a 
brutal best fit method. As a disadvantage, NutHeapAlloc is slow and 
consumes more CPU cycles than other memory allocation algorithms. So, 
avoiding heap allocation is always a good idea.

Harald






More information about the En-Nut-Discussion mailing list