TachyonUI
0.1.0
High-performance UI for building tools.
Toggle main menu visibility
Loading...
Searching...
No Matches
Allocation hooks and headless backends
Allocation hooks
Allocation hooks are your own memory functions, which the library then uses instead of its default ones.
Set them before
Initialize
:
#include <
gui_core/memory/gui_allocation_hooks.h
>
tachyon::AllocationHooks
hooks;
hooks.
allocate
= &MyAllocate;
// void* (size_t size, size_t alignment, void* user)
hooks.
reallocate
= &MyReallocate;
// void* (void* ptr, size_t size, size_t alignment, void* user)
hooks.
free
= &MyFree;
// void (void* ptr, void* user)
hooks.
user
= &myHeap;
app.SetAllocationHooks(hooks);
gui_allocation_hooks.h
tachyon::AllocationHooks
Memory functions a host gives the library, for the allocations that can be routed: Vulkan objects,...
Definition
gui_allocation_hooks.h:15
tachyon::AllocationHooks::free
void(*) free(void *ptr, void *user)
Frees ptr, which may be null.
Definition
gui_allocation_hooks.h:22
tachyon::AllocationHooks::user
void * user
passed to every call
Definition
gui_allocation_hooks.h:23
tachyon::AllocationHooks::allocate
void *(*) allocate(size_t size, size_t alignment, void *user)
Returns size bytes aligned to alignment (a power of two).
Definition
gui_allocation_hooks.h:17
tachyon::AllocationHooks::reallocate
void *(*) reallocate(void *ptr, size_t size, size_t alignment, void *user)
Resizes ptr, keeping its alignment; ptr may be null (then it allocates).
Definition
gui_allocation_hooks.h:20
The hooks cover:
Vulkan objects
VMA
vk-bootstrap
SDL
SDL's memory functions are shared by the whole process. SDL uses the hooks only if:
the GUI starts SDL
and SDL hasn't allocated anything yet
The hooks must be thread-safe, because drivers call them from their own threads.
They must outlive the GUI.
SDL keeps using them for a few allocations after
SDL_Quit
, so keep them alive for the whole process.
tachyon::TrackingAllocator
(
gui_core/memory/gui_tracking_allocator.h
) has ready-made hooks:
they count the allocations that are still live
they report leaks
Hooks()
returns them
#include <
gui_core/memory/gui_tracking_allocator.h
>
static
tachyon::TrackingAllocator
tracker;
// lives as long as the process
app.SetAllocationHooks(tracker.
Hooks
());
// ...
tracker.
ReportLeaks
();
// logs each allocation still live
tachyon::TrackingAllocator
Allocation hooks that count what is live, for finding leaks.
Definition
gui_tracking_allocator.h:15
tachyon::TrackingAllocator::ReportLeaks
size_t ReportLeaks() const
Logs a warning per live allocation; returns how many there are.
tachyon::TrackingAllocator::Hooks
AllocationHooks Hooks()
Hooks that allocate through this allocator; valid while it lives.
gui_tracking_allocator.h
Headless backends
Headless means running without a GPU or without a display.
NullGraphicsContext
(
gui_core/graphics/null/gui_null_graphics_context.h
) is a graphics backend without a GPU:
it draws nothing
the UI is still built, laid out and recorded
windows stay empty
NullWindowBackend
is a window backend without an OS:
input arrives only through the
Inject*
calls
Together they need no GPU and no display, for example in tests.
app.SetGraphicsBackend(std::make_unique<tachyon::NullGraphicsContext>());
app.SetWindowBackend(std::make_unique<tachyon::NullWindowBackend>());
They are also the smallest backends to start from when writing your own:
a graphics backend derives from
tachyon::GraphicsContext
a window backend derives from
tachyon::IWindowBackend
Previous: Rendering the UI into a host image
|
Integration
TachyonUI documentation
Integration
Generated by
1.18.0