![]() |
OS
v1.7.5
Documentation
|
The QuarkTS++ OS is designed to support the development of safe-critical embedded applications. Dynamic memory allocation is not permitted for kernel design, as it may result in out-of-storage run-time failures that are undesirable. However, some applications can be easily deployed using this allocation scheme, making a safe and portable implementation crucial for user code.
In a typical C++ environment, memory allocation can be achieved using standard new
and delete
operators as well as the C library functions like malloc()
and free()
. However, they may not be appropriate for most embedded applications, as they may not be available on small microcontrollers or could consume a substantial amount of code space. Furthermore, dynamic memory allocation has several implementation-defined behaviors and potential issues such as fragmentation.
To address these concerns, the OS offers its own memory management interface for dynamic allocation as a fully kernel-independent extension.
The allocation scheme works by subdividing a static array into smaller blocks and using the First-Fit approach.
If adjacent free blocks are available, the implementation combines them into a single larger block, minimizing the risk of fragmentation, making it suitable for applications that repeatedly allocate and free different sized blocks of RAM.
A memory pool ( qOS::mem::pool ) is a special resource that allows memory blocks to be dynamically allocated from a user-designated memory region. Instead of typical pools with fixed size block allocation, the pools in QuarkTS++ can be of any size, thereby the user is responsible for selecting the appropriate memory pool to allocate data with the same size.
The default memory management unit resides in a memory pool object. Also called the "default pool". The total amount of available heap space in the default memory pool is set by Q_DEFAULT_HEAP_SIZE
, which is defined in config.h
.
Besides the default pool, any number of additional memory pools can be defined. Like any other object in QuarkTS++, memory pools are referenced by handles, a variable of class qOS::mem::pool and should be initialized before using its own constructor or the qOS::mem::pool::setup() method.
From now on, user can allocate and free memory in the pool by calling qOS::mem::pool::alloc(), or qOS::mem::pool::free().
To keep track of the memory usage, the qOS::mem::pool::getFreeSize() method function returns the number of free bytes in the memory pool at the time the function is called.