Glossary · Automation software engineering and architecture
Memory allocation
Also known as: Memory assignment
German: Speicherzuweisung
In software engineering, memory allocation is the reservation of memory for program data, either statically at compile or link time, on the stack at function entry, or dynamically on the heap at run time.
- Software engineering
In one sentence
Memory allocation reserves memory for program data, statically at build time, on the stack or dynamically on the heap at run time.
Example
The PLC runtime allocates all process data and function block instances statically at download, so the cyclic task never requests memory while the machine runs.
How it applies
- Engineering: Real-time and safety-related software usually allocates memory statically or at startup, because Dynamic memory allocation at run time can fragment memory and has unpredictable timing. A Memory pool is a common compromise.
- Verification: Coding standards for embedded software restrict or forbid heap allocation after initialization; Static code analysis checks this rule.
- Documentation: System requirements and the software manual should state memory limits, for example the maximum number of recipes or alarms a controller can hold, so that users do not exceed what was allocated.
Static vs. dynamic allocation
Static allocation fixes the size and location of data before the program runs; it is predictable and easy to verify. Dynamic allocation requests memory while the program runs; it is flexible but can fail at run time and can cause a Memory leak if memory is not released.