[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Struct problem

From: David Brown
Subject: Re: [avr-gcc-list] Struct problem
Date: Mon, 2 Feb 2004 14:32:53 +0100

>As "David Brown" <address@hidden> wrote:

>>However, there are two rules regarding dynamic memory in small
>>embedded systems - 1) Don't use dynamic memory in small embedded
>>systems, and 2) if you really do have to use dynamic memory in small
>>embedded systems, don't use malloc() and free(), but write your own

>While I fully agree with 1), what's your reasoning for 2)?  I do
>understand that there might be reasons for it, but I don't think
>giving this as a general advise sounds right to me.

Basically, standard malloc() / free() implementations can (unless you are
very careful, or have particular paterns of usage - such as only allocating
at program startup, and never freeing since your program never ends (in
which case, why are you using dynamic memory in the first place?)) have
problems such as memory fragmentation, varying delays when allocating
memory, failed allocations, memory overheads, etc.  It is frequently better
to have memory pools for allocation of specifically-size elements, or other
specific code.  Of course, there are some types of code where you want to
use the standard dynamic memory allocation routines, but you do have to be

Since I am more a follower of rule (1), however, I have not actually used
malloc() and free() on such small processors - I am therefore happy to hear
other opinions.  There is nothing like a bit of discussion to be sure that
we have all thought through the relevant issues.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]