Allocation Spaces
The default memory configuration contains multiple allocation spaces (MSpaces). The wRTOS Subsystem, networking components, and each RTSS process and proxy process, have an internal MSpace for internal objects and bookkeeping, and an external MSpace for process allocations.
- Memory allocation requests from RTAPIs, including from C-Runtime libs, are allocated within the external allocation space (ExtMSpace).
- Memory needs from the Subsystem for internal objects are allocated within the internal allocation space (IntMSpace).
Memory is allocated from one of the process MSpaces unless the memory is required to stay over process exit, such as memory for IPC objects (like events and semaphores) and cross-process shared memory. Such allocations are made from the Subsystem’s MSpaces.
The diagram below depicts an example of memory allocation for an RTSS process/system process from the Windows Nonpaged Pool to external and internal MSpaces.
In the Windows Nonpaged Pool, black is memory allocated to the Local Pool.
In the Local Pool:
- Black is memory allocated from Windows but freely available to a process.
- Gray is memory allocated from the pool to the Pool Cache to fulfill small process memory requests.
- Red is large memory requests directly made by the process. Large requests bypass the Pool Cache to improve performance.
- The total pool memory is the sum of used/allocated memory plus free memory.
In the Pool Cache:
- Gray represents the free memory available to the process.
- Red represents memory explicitly allocated by the process.
Several MSpace default values can be configured in the wRTOS Settings or individually through RtssRun and the Task Manager.
A process’ MSpaces are allocated on the first request for memory. You can allocate the MSpaces of a process during process creation using RtssRun or Task Manager. This guarantees that your first memory allocation is deterministic. There are no global settings for this behavior. It can only be done per process.
A process’ MSpaces are allocated on the first request for memory. When you start a real-time process using RtssRun or Task Manager, MSpaces are always allocated at process startup before any code in the process executes. This does not happen when you use wRTOS Native or Managed APIs to start a process unless you pass the initial size of the process MSpaces to those APIs.
The table below lists the allocation spaces for various types of memory requests:
| Memory requests from... | Local memory |
|---|---|
| C-Runtime libs (new, malloc, realloc, calloc, etc.) | Process ExtMSpace |
| RtAllocateLocalMemoryEx | Process ExtMSpace |
| HeapAlloc/HeapReAlloc | Process ExtMSpace |
| VirtualAlloc | Process ExtMSpace |
| IPC (RtCreateSharedMemory, etc.) | System ExtMSpace |
| RtCreateProcess | Process IntMSpace |
| RtCreateThread | Process IntMSpace |
| RtCreateEvent, RtCreateSemaphore, … | System IntMSpace |