forked from RIOT-OS/RIOT
-
Notifications
You must be signed in to change notification settings - Fork 1
Static vs Dynamic Memory
Hauke Petersen edited this page Jan 17, 2014
·
7 revisions
In your c program you have to decide where the memory you want to use comes from. There are two ways to get memory in your c code:
- define static memory
- use dynamic memory (call malloc/free to get memory from the heap)
Both ways have some drawbacks which are listed here. If you want to analyze the static memory consumption of your code you can use otm.
- access the memory in one operation O(1) -> real time condition
- programmer needs to know the amount of memory on compile time
- leads to over and undersized buffers
- forces the programmer to think about the amount of need memory at compile time
- malloc and free are implemented in your libc (RIOT on ARM: newlib)
- run time behavior not predictable
- code can request the amount of memory it needs on run time
- on most platforms: the size of the heap is sizeof(RAM)-sizeof(static memory)
- if you reduce your usage of static memory your heap gets bigger
- on some platforms calling
free()
will not or not always make heap memory available again (see onetime_malloc() on MSP430 or the implementation of sbrk() for lpc2387) - programmer needs to handle failed memory allocation calls at runtime
- static code analysis is unable to find errors regarding memory management
RIOT - The friendly Operating System for the Internet of Things
Homepage | [GitHub] (https://github.com/RIOT-OS/) | Developers Mailing List | Users Mailing List | Twitter @RIOT_OS
- Family: ARM
- Board: Airfy Beacon
- Board: Arduino Due
- Board: CC2538DK
- Board: CC2650STK
- Board: HikoB Fox
- Board: IoT LAB M3
- Board: LimiFrog-v1
- Board: mbed_lpc1768
- Board: MSB-IoT
- Board: MSBA2
- Board: Nucleo-L1
- Board: Nucleo-F334
- Board: Nucleo-F303
- Board: Nucleo-F091
- Board: Mulle
- Board: OpenMote
- Board: PCA1000x (nRF51822 Development Kit)
- Board: Phytec phyWAVE-KW22
- Board: RFduino
- Board: SAMR21-xpro
- Board: SAML21-xpro
- Board: Seeeduino Arch-Pro
- Board: Spark Core
- Board: STM32F0discovery
- Board: STM32F3discovery
- Board: STM32F4discovery
- Board: UDOO
- Board: yunjia-nrf51822
- Board: Zolertia remote
- Family: ATmega
- Board: Arduino Mega2560
- Board: Arduino Uno
- Board: Arduino Duemilanove
- Family: MSP430
- Board: MSB-430H
- Board: TelosB
- Board: WSN430
- Board: Zolertia Z1
- Board: eZ430-Chronos
- Family: native
- Board: native
- Family: x86
- Board: Intel Galileo