95 inline uint32_t
align_up(uint32_t value, uint32_t align)
noexcept
97 return (value + align - 1U) & ~(align - 1U);
107 for (uint32_t i = 0; i < hdr->entry_count; ++i) {
108 if (hdr->entries[i].occupied
110 return &hdr->entries[i];
138 if (aligned_bump + size > object_region_capacity) {
142 const uint32_t idx = hdr->entry_count;
143 auto& entry = hdr->entries[idx];
146 entry.offset = aligned_bump;
148 entry.occupied =
true;
177 const uint32_t idx = hdr->entry_count;
178 auto& entry = hdr->entries[idx];
181 entry.offset = UINT32_MAX;
182 entry.size = UINT32_MAX;
183 entry.occupied =
true;
201 template <
typename T>
204 return ::MayaFlux::Reflect::short_type_name<T>();
217 static_cast<int>(name.size()), name.data(),
count);
228#define MF_LIVE_EXPOSE(key, ptr) ::MayaFlux::expose_live((key), (ptr))
230#define MF_LIVE_EXPOSE(key, ptr) ((void)0)
245#define MF_LIVE_EXPOSE_AUTO(ptr) \
247 using _MfT = typename decltype(ptr)::element_type; \
248 static std::atomic<uint32_t> s_live_counter { 0 }; \
249 char _mf_key[::MayaFlux::internal::LIVE_ARENA_KEY_MAX]; \
250 ::MayaFlux::internal::live_format_key( \
252 ::MayaFlux::internal::live_type_name<_MfT>(), \
253 s_live_counter.fetch_add(1)); \
254 ::MayaFlux::expose_live(_mf_key, (ptr)); \
257#define MF_LIVE_EXPOSE_AUTO(ptr) ((void)0)
271#define MF_LIVE_EXPOSE_NAMED(name, ptr) \
273 static std::atomic<uint32_t> s_live_counter { 0 }; \
274 char _mf_key[::MayaFlux::internal::LIVE_ARENA_KEY_MAX]; \
275 ::MayaFlux::internal::live_format_key( \
277 std::string_view { (name) }, \
278 s_live_counter.fetch_add(1)); \
279 ::MayaFlux::expose_live(_mf_key, (ptr)); \
282#define MF_LIVE_EXPOSE_NAMED(name, ptr) ((void)0)
302template <
typename T,
typename... Args>
303std::shared_ptr<T>
make_live(
const char* key, Args&&... args)
307 static_cast<uint32_t
>(
sizeof(T)),
308 static_cast<uint32_t
>(
alignof(T)));
314 T* obj = ::new (mem) T(std::forward<Args>(args)...);
315 return std::shared_ptr<T>(obj, [](T*) { });
331bool expose_live(
const char* key,
const std::shared_ptr<T>& obj)
noexcept
383 return std::shared_ptr<T>(
static_cast<T*
>(
ptr), [](T*) { });
constexpr std::size_t LIVE_ARENA_KEY_MAX
Maximum length of a live arena key, including null terminator.
uint32_t align_up(uint32_t value, uint32_t align) noexcept
Aligns value up to the next multiple of align.
constexpr std::size_t LIVE_ARENA_MAX_ENTRIES
Maximum number of objects that can be registered in the live arena.
constexpr std::string_view live_type_name() noexcept
Extracts the unqualified type name from a compiler-generated function signature.
uint32_t g_live_arena_bump
Byte offset of the bump pointer from the start of the object region.
constexpr std::size_t LIVE_ARENA_CAPACITY
Default capacity of the live arena in bytes.
void live_format_key(char *buf, std::string_view name, uint32_t count) noexcept
Formats a live arena key as "TypeName_N" into buf.
LiveArenaHeader * live_arena_header() noexcept
Returns a pointer to the header block at the start of arena storage.
unsigned char * live_arena_object_region() noexcept
Returns a pointer to the object region (immediately after the header).
bool live_arena_expose(const char *key, std::shared_ptr< void > shared) noexcept
Registers an externally owned shared_ptr under key.
LiveArenaEntry * live_arena_find(const char *key) noexcept
Locates an existing directory entry by key.
void * live_arena_alloc(const char *key, uint32_t size, uint32_t alignment) noexcept
Allocates size bytes from the arena with alignment.
unsigned char g_live_arena_storage[LIVE_ARENA_CAPACITY]
Raw backing storage for the live arena with external linkage.
std::shared_ptr< void > g_live_arena_shared_ptrs[LIVE_ARENA_MAX_ENTRIES]
Shared ownership table for objects registered via expose_live.
MAYAFLUX_API void * live_cast_impl(const char *key) noexcept
Internal implementation for live_cast.
bool expose_live(const char *key, const std::shared_ptr< T > &obj) noexcept
Exposes an existing shared_ptr-managed object to the live arena under key.
MAYAFLUX_API void live_arena_dump() noexcept
Dumps all live arena entries to stderr.
std::shared_ptr< T > live_cast(const char *key) noexcept
Retrieves a live-arena object by key as a shared_ptr<T>.
std::shared_ptr< T > make_live(const char *key, Args &&... args)
Constructs a T in-place inside the live arena and registers it under key.
Main namespace for the Maya Flux audio engine.
char key[LIVE_ARENA_KEY_MAX]
Single directory entry mapping a string key to a location within the arena.