how bad is it to use dynamic datastuctures on an embedded system?

Viewed 16378

So in an embedded systems unit, that i'm taking at uni next year, we will learn that dynamic data structures are a bad thing to have in an embedded system program. but the lecture notes don't go into why.

Now i'm working on a moderate scale, embedded systems\ 'LURC' controller, mostly just takes advantages of the peripheral of the "Butterfly" demo board for the AVR169MEGA. produced 4 PWM signals to contol servo's and ESC. and also to provide an 9 seg LCD screen.

Now I can't think of anybetter way to store instructions as they are recieved vial USART serial, than a queue. esp for things where I'll need to wait until an unknown amount of data has been recieved: eg a string to display on the LCD screen.

so why don't you uses dynamic data structures on a microcontroller in a embedded systems? Is it just that you're on a heavily memory restricted enviroment, and have to be sure your mallocs are succeeding?

9 Answers

I do not think that utilizing dynamic allocation in embedded systems is a bad idea. I just want to say that there are some points you need to avoid.

  1. Be careful with your HEAP size. If you exceed the MAX_HEAP limit described in your linker file, a hardware exception might occur.
  2. Allocating an area after the system started up may cause delays in your time-dependent tasks. So, you better allocate the area you want during the initialization phase. That's not a rule, just a suggestion:)
  3. Think again if you can solve the problem you are facing without dynamic allocation.

Also, I think dynamic allocation is one of the superior features of programming languages. Thus, I can't think of designing an application that is well structured without it :)

Related