MayaFlux 0.4.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 122 of file LiveArena.hpp.

123 {
124 auto* hdr = live_arena_header();
125
126 if (hdr->entry_count >= LIVE_ARENA_MAX_ENTRIES) {
127 return nullptr;
128 }
129
130 if (live_arena_find(key)) {
131 return nullptr;
132 }
133
134 const auto object_region_capacity = static_cast<uint32_t>(LIVE_ARENA_CAPACITY - sizeof(LiveArenaHeader));
135
136 const uint32_t aligned_bump = align_up(g_live_arena_bump, alignment);
137
138 if (aligned_bump + size > object_region_capacity) {
139 return nullptr;
140 }
141
142 const uint32_t idx = hdr->entry_count;
143 auto& entry = hdr->entries[idx];
144 std::strncpy(entry.key, key, LIVE_ARENA_KEY_MAX - 1);
145 entry.key[LIVE_ARENA_KEY_MAX - 1] = '\0';
146 entry.offset = aligned_bump;
147 entry.size = size;
148 entry.occupied = true;
149
150 g_live_arena_bump = aligned_bump + size;
151 ++hdr->entry_count;
152
153 return live_arena_object_region() + aligned_bump;
154 }
constexpr std::size_t LIVE_ARENA_KEY_MAX
Maximum length of a live arena key, including null terminator.
Definition LiveArena.hpp:17
uint32_t g_live_arena_bump
Byte offset of the bump pointer from the start of the object region.
Definition LiveArena.cpp:8
LiveArenaHeader * live_arena_header() noexcept
Returns a pointer to the header block at the start of arena storage.
Definition LiveArena.hpp:79
unsigned char * live_arena_object_region() noexcept
Returns a pointer to the object region (immediately after the header).
Definition LiveArena.hpp:87

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

Referenced by MayaFlux::make_live().

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