C
Improving startup time using a preload allocator
Preloading resources in the device setup phase improves the startup time of an application. In the project configuration, assets can be configured to be loaded into RAM by default by specifyinc an OnStartup
cache policy: ImageFiles.MCU.resourceCachePolicy, MCU.Config.fontFilesCachePolicy
This example reserves space from the SDRAM for the preloadable resources with SDRAM_PRELOAD region in the linker script. The symbols __preloadSdramStart
and __preloadSdramEnd
are defined for the resource preloading to determine the start and end address of the preload section:
__preloadSdramStart = ORIGIN(SDRAM_PRELOAD); __preloadSdramEnd = ORIGIN(SDRAM_PRELOAD) + LENGTH(SDRAM_PRELOAD);
Example platform adaptation creates pointers to the linker symbols:
extern uint8_t __preloadSdramStart; extern uint8_t __preloadSdramEnd; void *preloadSdramStart = &__preloadSdramStart; void *preloadSdramEnd = &__preloadSdramEnd;
By default the resources use DefaultPreload allocation type. Preload start and end address are used by the ExampleReversePreloadAllocator to determine the maximum size of the preload section.
The memory allocator for the platform context has to be extended to handle the DefaultPreload type:
PlatformInterface::MemoryAllocator *ExamplePlatform::memoryAllocator( PlatformInterface::MemoryAllocator::AllocationType type) { static ExampleMemoryAllocator exampleMemoryAllocator; static ExampleReversePreloadAllocator<4> examplePreloadAllocator(preloadSdramEnd, preloadSdramStart); static PlatformInterface::MemoryAllocator defaultMemoryAllocator; switch (type) { ... case PlatformInterface::MemoryAllocator::DefaultPreload: return &examplePreloadAllocator; ...
Preloading can be disabled by returning nullptr
from the memory allocator for the DefaultPreload allocation type.
Available under certain Qt licenses.
Find out more.