Re: STL containers and managing memory allocation in embedded systems



On Fri, 31 Mar 2006 16:39:46 +0200, Zara <yozara@xxxxxxxx> wrote:

On 31 Mar 2006 13:32:07 GMT, Hans-Bernhard Broeker
<broeker@xxxxxxxxxxxxxxxxxxxxx> wrote:

2. But how to manage memory allocation in containers for embedded
systems?

Primarily by not using them.

Seems too radical.

An embedded system may use perfectly dynamic memory as long as it is
able to recover from lack of memory or,at least, not enter an unstable
state. Some Denial-Of-Sservice may be allowed as long as the whole
system continues to work.

So you need at least two separate dynamic memory areas, one that can
overflow, the other that can't.

The main problem is that *every* allocation must be checked, wheteher
with exceptions or with null pointer return.

And what do you realistically do when you detect this condition ?
IMHO, it is a bad design if you end up in this situation.

In a single task environment you might even be able to unwind some
less important allocations (provided that unwinding does not itself
use dynamic memory :-), but how do you expect to do anything useful in
a multitasking environment with a shared dynamic memory ?

In practice, usually the only realistic thing to do, when even a small
allocation fails is to restart the system, which in several cases is a
severe malfunction.

Paul

.