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?
Memory allocation can fail. This may be because there is insufficient memory available (in the heap) to fulfill the request. It may also be caused by fragmentation; there is enough memory available, but no contiguous chunks are is large enough. The function is commonly not reentrant.
These facts make dynamic memory allocation a dangerous trade-off that needs to be designed in from the start. One rule is to only allocate at start up, however the downside of even that rule is that you lose visibility of how much memory your program needs in the worst case.
Chapter 3 shows that the program code, program data, and system stack occupy the physical memory after program initialization completes. Either the RTOS or the kernel typically uses the remaining physical memory for dynamic memory allocation.
Specialized structures, called data structures, can be used for various applications such as messaging between two embedded systems and storing data gathered from a sensor in noncontiguous memory locations. Structures are useful when we need to access the registers of a memory-mapped microcontroller peripheral.
There are a number of reasons not to use malloc (or equivalent) in an embedded system.
Best of all - if you do not dynamically allocate memory then you can't get memory leaks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With