C
MemoryAllocator Class
class Qul::PlatformInterface::MemoryAllocatorThis class provides an abstract interface for memory allocation. More...
Header: | #include <platforminterface/memoryallocator.h> |
Since: | Qt Quick Ultralite (Platform) 1.9 |
Public Types
enum | AllocationType { Default, Image, TextCache, DefaultPreload, SparkCache, …, Custom } |
enum | UsagePattern { WriteOnce, WriteRarely, WriteFrequently } |
Public Functions
virtual void | acquire(void *ptr, std::size_t offset, std::size_t size) |
virtual void * | allocate(std::size_t size, Qul::PlatformInterface::MemoryAllocator::UsagePattern usagePattern = WriteRarely) |
virtual void | free(void *ptr) |
virtual void * | reallocate(void *ptr, std::size_t size) |
virtual void | release(void *ptr, std::size_t offset, std::size_t size) |
Detailed Description
This class is used for certain kind of memory allocations that might be significant in size. The platform might usually prefer to have such memory allocated in custom memory regions such as VRAM, SDRAM, and so on.
Qt Quick Ultralite uses Qul::Platform::qul_malloc and related APIs for smaller allocations.
Member Type Documentation
enum MemoryAllocator::AllocationType
This enum specifies the type of the memory allocation.
Constant | Value | Description |
---|---|---|
Qul::PlatformInterface::MemoryAllocator::Default | 0 | The default type for large allocations. |
Qul::PlatformInterface::MemoryAllocator::Image | 1 | Memory allocation to store images created using the Qul::Image API. |
Qul::PlatformInterface::MemoryAllocator::TextCache | 2 | Memory allocation for the text cache, which caches multiple glyphs in a single image to avoid draw call overhead. |
Qul::PlatformInterface::MemoryAllocator::DefaultPreload | 3 | Memory allocation for resources that are copied at startup from flash to RAM |
Qul::PlatformInterface::MemoryAllocator::SparkCache | 4 | Preallocated cache buffer for Monotype Spark font engine, if MCU.Config.fontCacheSize is set. |
Qul::PlatformInterface::MemoryAllocator::SparkHeap | 5 | Preallocated heap buffer for Monotype Spark font engine, if MCU.Config.fontHeapSize is set. |
Qul::PlatformInterface::MemoryAllocator::QmlDynamicObjects | 6 | Memory allocation for dynamically created objects by Loader, ListView, Repeater etc. Acquire and release methods are not called for this type. |
Qul::PlatformInterface::MemoryAllocator::Custom | 128 | This and higher enum values are reserved for platform-specific memory areas. |
enum MemoryAllocator::UsagePattern
This enum specifies how to use the allocated memory.
Constant | Value | Description |
---|---|---|
Qul::PlatformInterface::MemoryAllocator::WriteOnce | 0 | The allocation will be written to only once. |
Qul::PlatformInterface::MemoryAllocator::WriteRarely | 1 | The allocation will be written to less frequently than it will be read from. |
Qul::PlatformInterface::MemoryAllocator::WriteFrequently | 2 | The allocation will be written to more frequently than it will be read from. |
Member Function Documentation
[virtual]
void MemoryAllocator::acquire(void *ptr, std::size_t offset, std::size_t size)
Acquires write access to a block of memory allocated by allocate.
ptr is the pointer to the memory block to be accessed. It must be returned by allocate or reallocate.
offset is the memory range used for the allocation that will be written to, and size is the size of the memory range.
After the memory has been written to, release must be called with the same parameters.
The default implementation doesn't do anything.
See also allocate and release.
[virtual]
void *MemoryAllocator::allocate(std::size_t size, Qul::PlatformInterface::MemoryAllocator::UsagePattern usagePattern = WriteRarely)
Allocates a chunk of memory.
This method allocates memory of the given size, with expected usage pattern usagePattern.
acquire must be called before writing to the allocated memory.
The default implementation uses Qul::Platform::qul_malloc.
See also free and reallocate.
[virtual]
void MemoryAllocator::free(void *ptr)
Frees a memory block allocated by allocate.
ptr is the pointer to the memory block to be freed.
The default implementation uses Qul::Platform::qul_free.
See also allocate and reallocate.
[virtual]
void *MemoryAllocator::reallocate(void *ptr, std::size_t size)
Attempt to resize a memory block allocated with allocate.
ptr is the pointer the the previously allocated memory block, and size (in bytes) is the new size for the memory block.
If ptr is NULL
, this is equivalent to a call to allocate with the given size and the default usage pattern.
Returns a NULL
if there is not enough memory to satisfy the request. In this case, ptr will not be freed.
The default implementation uses Qul::Platform::qul_realloc.
[virtual]
void MemoryAllocator::release(void *ptr, std::size_t offset, std::size_t size)
Releases write access that was acquired using acquire.
ptr is the pointer to the memory block to be accessed. It must be returned by allocate or reallocate.
offset is the memory range used for the allocation that will be written to, and size is the size of the memory range.
The default implementation doesn't do anything.
See also acquire.
Available under certain Qt licenses.
Find out more.