1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-15 01:23:49 +01:00

doc/static-vs-dynamic-memory: style and spelling fixes + updates

To current status quo.
This commit is contained in:
Martine Lenders 2024-12-06 12:56:48 +01:00
parent 314b3374c6
commit f762232a12
No known key found for this signature in database
GPG Key ID: 2134D77A5336DD80

View File

@ -1,29 +1,29 @@
This page discusses the usage of memory on restricted devices Static vs. Dynamic Memory
============================================================= =========================
In your c program you have to decide where the memory you want to use comes from. 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: There are two ways to get memory in your C code:
1. define static memory 1. Define static memory.
2. use dynamic memory (call malloc/free to get memory from the heap) 2. Use dynamic memory (call `malloc()`/`free()` to get memory from the heap).
Both ways have some drawbacks which are listed here. 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](https://github.com/LudwigOrtmann/otm). If you want to analyze the static memory consumption of your code you can use [otm](https://github.com/LudwigOrtmann/otm) or `make cosy`.
static memory Static memory
------------- -------------
* access the memory in one operation O(1) -> real time condition * Access the memory in one operation O(1) ⇒ real time condition
* programmer needs to know the amount of memory on compile time * Programmer needs to know the amount of memory on compile time
* leads to over and undersized buffers * Leads to over and undersized buffers
* forces the programmer to think about the amount of need memory at compile time * Forces the programmer to think about the amount of need memory at compile time
dynamic memory Dynamic memory
-------------- --------------
* malloc and free are implemented in your libc (RIOT on ARM: newlib) * `malloc()` and `free()` are implemented in your `libc` (RIOT on ARM: `newlib`/`picolib`)
* run time behavior not predictable * Runtime behavior is not predictable
* code can request the amount of memory it needs on run time * Code can request the amount of memory it needs on runtime
* on most platforms: the size of the heap is sizeof(RAM)-sizeof(static memory) * 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 * 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) * On some platforms calling `free()` will not or not always make heap memory available again (see @ref oneway_malloc on MSP430)
* programmer needs to handle failed memory allocation calls at runtime * Programmer needs to handle failed memory allocation calls at runtime
* static code analysis is unable to find errors regarding memory management * Static code analysis is unable to find errors regarding memory management