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

Ole Reinhardt ole.reinhardt at embedded-it.de
Mon Aug 11 11:27:45 CEST 2008


Hi!

> 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.

Ok, so let's change the code to completely avoid strtok_r and alloca if
possible. Especially the alloca can't be realy avoided at this point, so
we need at least an malloc or a static array, which will be less
ressource efficient than alloca.

Perhaps we should implement some kind of a slice allocator for these
class of problems. A slice allocator is a function that initialy
allocates a little block of heap and uses it's own far more simple
allocation routine to give small slices of this heap block to
applications. If at any time the application requests more heap than
available the slice allocator will request another larger block an
manage this one as well.

In general I would not totaly avoid alloca. Especially for very short
strings and similar use cases it would make sense in a lot places. Even
for systems with little stack. If we avoid it in the system code but
allow it for user applications would'nt it be worth to implement a
geneal alloca function (or better a NutAlloca function) independant from
any compiler lib?

> 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.

Indeed :)

Regards,

Ole

-- 
 _____________________________________________________________
|                                                             |
| 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