Skip to content

cvedia::rt::BufferLuaRegistry

Thread-local registry for tracking BufferLua objects created during a frame. More...

#include <bufferlua_registry.h>

Public Classes

Name
struct FrameCleanupGuard
RAII guard for automatic cleanup at scope exit.

Public Functions

Name
BufferLuaRegistry & current()
Get the thread-local registry instance for the current thread.
void registerBuffer(std::shared_ptr< BufferLua > const & buf)
Register a BufferLua object for cleanup at frame end.
void invalidateAll()
Invalidate all registered BufferLua objects and clear the registry.
size_t size() const
Get the number of registered BufferLua objects.
BufferLuaRegistry() =default

Friends

Name
BufferLuaRegistry & current_registry_friend()

Detailed Description

class cvedia::rt::BufferLuaRegistry;

Thread-local registry for tracking BufferLua objects created during a frame.

This registry enables deterministic cleanup of BufferLua objects at frame boundaries. When onRunFunc() returns, all registered BufferLua objects are invalidated, releasing their underlying buffer memory immediately rather than waiting for Lua's GC.

Lua code attempting to use invalidated buffers will get graceful "Buffer is invalid" errors via the existing lock_or_error() mechanism.

Public Functions Documentation

function current

static BufferLuaRegistry & current()

Get the thread-local registry instance for the current thread.

Return: Reference to the current thread's registry.

function registerBuffer

void registerBuffer(
    std::shared_ptr< BufferLua > const & buf
)

Register a BufferLua object for cleanup at frame end.

Parameters:

  • buf Shared pointer to the BufferLua object to register.

The registry keeps a shared_ptr to ensure objects stay alive during invalidateAll(), even if Lua GC runs early.

function invalidateAll

void invalidateAll()

Invalidate all registered BufferLua objects and clear the registry.

Called after onRunFunc() returns. Each registered BufferLua is invalidated (valid=false, buffer_=nullptr) so it releases memory but Lua pointers don't dangle until GC collects them.

function size

size_t size() const

Get the number of registered BufferLua objects.

Return: Number of currently registered buffers.

function BufferLuaRegistry

BufferLuaRegistry() =default

Friends

friend current_registry_friend

friend BufferLuaRegistry & current_registry_friend();