DEKI/ENGINE docs
Deki 0.19.0
Modular C++ 2D engine for embedded displays and desktop
Loading...
Searching...
No Matches
Deki::HostMemoryProvider Class Reference

Memory provider over the C heap (malloc/free), for any host with a normal C library heap: the editor, desktop and simulator builds, tests. More...

#include <deki/providers/HostMemoryProvider.h>

Inherits Deki::IMemoryProvider.

Public Member Functions

 HostMemoryProvider ()=default
 ~HostMemoryProvider () override=default
bool Initialize () override
 Returns false on failure.
void Shutdown () override
bool Serves (Memory::Region region) const override
 True when the board can place memory in region.
void * Allocate (Memory::Region region, size_t bytes, bool needsDma) override
 Allocates bytes from region, or returns nullptr, including for a region the board does not serve; it never substitutes another region.
void Free (Memory::Region region, void *ptr) override
 Frees a block from region.
size_t GetAvailable (Memory::Region region) const override
 Bytes still free in region, or 0 when the platform cannot measure it.
size_t GetRawBlockSize (void *ptr) const override
 Usable size of a block from AllocateRaw, or 0 when the platform cannot say.
Public Member Functions inherited from Deki::IMemoryProvider
virtual ~IMemoryProvider ()=default
virtual void * AllocateRaw (size_t size)
 Allocates size bytes, or returns nullptr.
virtual void FreeRaw (void *ptr)
 Frees a block from AllocateRaw. Override both or neither.

Detailed Description

Memory provider over the C heap (malloc/free), for any host with a normal C library heap: the editor, desktop and simulator builds, tests.

Constructor & Destructor Documentation

◆ HostMemoryProvider()

Deki::HostMemoryProvider::HostMemoryProvider ( )
default

◆ ~HostMemoryProvider()

Deki::HostMemoryProvider::~HostMemoryProvider ( )
overridedefault

Member Function Documentation

◆ Initialize()

bool Deki::HostMemoryProvider::Initialize ( )
inlineoverridevirtual

Returns false on failure.

Implements Deki::IMemoryProvider.

◆ Shutdown()

void Deki::HostMemoryProvider::Shutdown ( )
inlineoverridevirtual

Implements Deki::IMemoryProvider.

◆ Serves()

bool Deki::HostMemoryProvider::Serves ( Memory::Region region) const
inlineoverridevirtual

True when the board can place memory in region.

A platform with one heap answers true for every region it can satisfy: where all memory is equally fast, "external" without PSRAM is the same place as "internal". Memory asks once at startup to report what the board has.

Implements Deki::IMemoryProvider.

◆ Allocate()

void * Deki::HostMemoryProvider::Allocate ( Memory::Region region,
size_t bytes,
bool needsDma )
inlineoverridevirtual

Allocates bytes from region, or returns nullptr, including for a region the board does not serve; it never substitutes another region.

needsDma means a DMA engine must be able to read the block, in any region: a framebuffer must be reachable in internal RAM or PSRAM alike.

One entry point, not a virtual per region, because packages can define new regions (such as "rtc") without an engine release. A provider switches on region.id, a compile-time constant, and returns nullptr for any it does not know.

Implements Deki::IMemoryProvider.

◆ Free()

void Deki::HostMemoryProvider::Free ( Memory::Region region,
void * ptr )
inlineoverridevirtual

Frees a block from region.

The region comes from the allocation's own header, so callers never pass it themselves.

Implements Deki::IMemoryProvider.

◆ GetAvailable()

size_t Deki::HostMemoryProvider::GetAvailable ( Memory::Region region) const
inlineoverridevirtual

Bytes still free in region, or 0 when the platform cannot measure it.

It appears in the startup line and in every out-of-memory message, so a provider returning 0 should say in a comment that 0 means "unknown", not "exhausted".

Implements Deki::IMemoryProvider.

◆ GetRawBlockSize()

size_t Deki::HostMemoryProvider::GetRawBlockSize ( void * ptr) const
inlineoverridevirtual

Usable size of a block from AllocateRaw, or 0 when the platform cannot say.

There is no header, so the heap is asked (heap_caps_get_allocated_size on ESP-IDF, _msize on Windows). Only keeps the byte total right on free; 0 costs accuracy in Memory::LogStats and nothing else.

Reimplemented from Deki::IMemoryProvider.


The documentation for this class was generated from the following file: