Memory Manager Initialization#
Startup Sequence#
The Memory Manager follows a specific initialization sequence integrated with the SL Main/SL System framework. You must initialize Memory Manager early in the application startup sequence, before any memory allocation operations are performed:
Memory Manager Pre-Initialization: In C++ applications, the system automatically calls
sl_memory_init()before any C++ static constructors, using the .preinit_array section (GCC) or early dynamic initialization (IAR).SL System/SL Main Initialization: The system automatically calls
sl_memory_init()during platform initialization. It initializes early, before most SiSDK components and the application, because other components might need to perform dynamic allocations during their initialization.Components and Application Memory Allocation: Other SiSDK components and the application can allocate permanent memory blocks during their initialization.
Runtime Memory Operations: After the overall system initialization is complete, runtime memory operations can occur at any time through the Memory Manager constructs: dynamic allocation, memory pools, and dynamic reservation.
Initialization API#
sl_status_t sl_memory_init(void);Description: Initializes the Memory Manager module and sets up the heap structure.
Parameters: None
Return Values:
SL_STATUS_OK: Initialization successfulSL_STATUS_FAIL: Initialization failed
Example Usage:
#include "sl_memory_manager.h"
int main(void) {
// Initialize Memory Manager early in startup
sl_status_t status = sl_memory_init();
if (status != SL_STATUS_OK) {
// Handle initialization error
return -1;
}
// Now safe to use memory allocation functions
void *ptr = sl_malloc(100);
// ... rest of application
}