The cost of malloc()

When allocating a chunk of memory with malloc(), there is always some memory overhead associated with the heap control structures. Also, the minimum memory allocation unit is typically larger then one byte.

Because of that, sometimes it could be more efficient to allocate a static data of the maximum size rather then a dynamic data of the required size.

I understand that those things are implementation dependent. However, from the common sense standpoint, it shouldn't be too different for the MCUs and C/C++ compilers of the same class.

Is it possible to make any general assumptions about the behavior of malloc for, say, 8-bitters?

VLV

Reply to
Vladimir Vassilevsky
Loading thread data ...

It is not only the space requirement of malloc, but also the hard to predict timing requirement. It depends on your problem whether you can avoid dynamic data. Meaning if the problem is solvable without, I use static data.

Rene

--
Ing.Buero R.Tschaggelar - http://www.ibrtses.com
& commercial newsgroups - http://www.talkto.net
Reply to
Rene Tschaggelar

Op Mon, 16 Apr 2007 01:45:29 +0200 schreef Vladimir Vassilevsky :

A heap is not required. Also, for purposes of determinism, real-time systems (should) tend to avoid heap-based malloc.

Red Hat's newlib uses Doug Lea's implementation. The 8051 and AVR versions of IAR clib use a simple walk-to-end algorithm at first, then first-fit sequential search.

--
Gemaakt met Opera's revolutionaire e-mailprogramma:  
http://www.opera.com/mail/
Reply to
Boudewijn Dijkstra

Another thing to keep in mind is that some 8 bitters have poor support for indirection, so using dynamic pointers may involve many extra instructions to move values in and out of dedicated index registers.

Reply to
Arlet

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.