C

MemoryAllocator Class

class Qul::PlatformInterface::MemoryAllocator

This 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, 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.

ConstantValueDescription
Qul::PlatformInterface::MemoryAllocator::Default0The default type for large allocations.
Qul::PlatformInterface::MemoryAllocator::Image1Memory allocation to store images created using the Qul::Image API.
Qul::PlatformInterface::MemoryAllocator::TextCache2Memory allocation for the text cache, which caches multiple glyphs in a single image to avoid draw call overhead.
Qul::PlatformInterface::MemoryAllocator::Custom1024This and higher enum values are reserved for platform-specific memory areas.

enum MemoryAllocator::UsagePattern

This enum specifies how to use the allocated memory.

ConstantValueDescription
Qul::PlatformInterface::MemoryAllocator::WriteOnce0The allocation will be written to only once.
Qul::PlatformInterface::MemoryAllocator::WriteRarely1The allocation will be written to less frequently than it will be read from.
Qul::PlatformInterface::MemoryAllocator::WriteFrequently2The 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 calls Qul::Platform::PlatformContext::waitUntilAsyncReadFinished.

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 nullptr, this is equivalent to a call to allocate with the given size and the default usage pattern.

Returns a nullptr 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.

See also allocate and free.

[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 calls Qul::Platform::PlatformContext::flushCachesForAsyncRead.

See also acquire.

Available under certain Qt licenses.
Find out more.