MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ live_arena_alloc()

void * MayaFlux::internal::live_arena_alloc ( const char *  key,
uint32_t  size,
uint32_t  alignment 
)
inlinenoexcept

Allocates size bytes from the arena with alignment.

Writes a directory entry under key. Returns nullptr if the arena is full, the key is already registered, or capacity is exceeded.

Definition at line 146 of file LiveArena.hpp.

147 {
148 auto* hdr = live_arena_header();
149
150 if (hdr->entry_count >= LIVE_ARENA_MAX_ENTRIES) {
151 return nullptr;
152 }
153
154 if (live_arena_find(key)) {
155 return nullptr;
156 }
157
158 const auto object_region_capacity = static_cast<uint32_t>(LIVE_ARENA_CAPACITY - sizeof(LiveArenaHeader));
159
160 const uint32_t aligned_bump = align_up(g_live_arena_bump, alignment);
161
162 if (aligned_bump + size > object_region_capacity) {
163 return nullptr;
164 }
165
166 const uint32_t idx = hdr->entry_count;
167 auto& entry = hdr->entries[idx];
168 std::strncpy(entry.key, key, LIVE_ARENA_KEY_MAX - 1);
169 entry.key[LIVE_ARENA_KEY_MAX - 1] = '\0';
170 entry.offset = aligned_bump;
171 entry.size = size;
172 entry.occupied = true;
173
174 g_live_arena_bump = aligned_bump + size;
175 ++hdr->entry_count;
176
177 return live_arena_object_region() + aligned_bump;
178 }
bool size
constexpr std::size_t LIVE_ARENA_KEY_MAX
Maximum length of a live arena key, including null terminator.
Definition LiveArena.hpp:34
uint32_t g_live_arena_bump
Byte offset of the bump pointer from the start of the object region.
Definition LiveArena.cpp:20
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).

References align_up(), g_live_arena_bump, LIVE_ARENA_CAPACITY, live_arena_find(), live_arena_header(), LIVE_ARENA_KEY_MAX, LIVE_ARENA_MAX_ENTRIES, live_arena_object_region(), and size.

Referenced by MayaFlux::make_live().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: