Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resources for memory management in embedded application

How should I manage memory in my mission critical embedded application?

I found some articles with google, but couldn't pinpoint a really useful practical guide.

The DO-178b forbids dynamic memory allocations, but how will you manage the memory then? Preallocate everything in advance and send a pointer to each function that needs allocation? Allocate it on the stack? Use a global static allocator (but then it's very similar to dynamic allocation)?

Answers can be of the form of regular answer, reference to a resource, or reference to good opensource embedded system for example.

clarification: The issue here is not whether or not memory management is availible for the embedded system. But what is a good design for an embedded system, to maximize reliability.

I don't understand why statically preallocating a buffer pool, and dynamically getting and dropping it, is different from dynamically allocating memory.

like image 497
Elazar Leibovich Avatar asked Mar 18 '10 12:03

Elazar Leibovich


People also ask

How is memory managed in embedded systems?

In general, a kernel's memory management responsibilities include: Managing the mapping between logical (physical) memory and task memory references. Determining which processes to load into the available memory space. Allocating and deallocating of memory for processes that make up the system.

What is resource in embedded system?

Resource in embedded system can be defined as a hardware-controlled object that interacts with embedded software. The hardware-control object consists of interface memory for the communication between hardware and software and interrupts from hardware.

What are the memory management issues in embedded code?

These are often due to the challenges of manual memory management. Here are a few common issues found when having to manually manage memory in code. The program has allocated heap memory but failed to free that piece of memory. Data on the heap must be allocated and de-allocated manually, using malloc and free.

What is application memory management?

Application memory management. Application memory management involves supplying the memory needed for a program's objects and data structures from the limited resources available, and recycling that memory for reuse when it is no longer required.


1 Answers

As someone who has dealt with embedded systems, though not to such rigor so far (I have read DO-178B, though):

  • If you look at the u-boot bootloader, a lot is done with a globally placed structure. Depending on your exact application, you may be able to get away with a global structure and stack. Of course, there are re-entrancy and related issues there that don't really apply to a bootloader but might for you.
  • Preallocate, preallocate, preallocate. If you can at design-time bind the size of an array/list structure/etc, declare it as a global (or static global -- look Ma, encapsulation).
  • The stack is very useful, use it where needed -- but be careful, as it can be easy to keep allocating off of it until you have no stack space left. Some code I once found myself debugging would allocate 1k buffers for string management in multiple functions...occasionally, the usage of the buffers would hit another program's stack space, as the default stack size was 4k.
  • The buffer pool case may depend on exactly how it's implemented. If you know you need to pass around fixed-size buffers of a size known at compile time, dealing with a buffer pool is likely more easy to demonstrate correctness than a complete dynamic allocator. You just need to verify buffers cannot be lost, and validate your handling won't fail. There seem to be some good tips here: http://www.cotsjournalonline.com/articles/view/101217

Really, though, I think your answers might be found in joining http://www.do178site.com/

like image 167
Arthur Shipkowski Avatar answered Sep 21 '22 23:09

Arthur Shipkowski