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 126 of file LiveArena.hpp.

127 {
128 auto* hdr = live_arena_header();
129
130 if (hdr->entry_count >= LIVE_ARENA_MAX_ENTRIES) {
131 return nullptr;
132 }
133
134 if (live_arena_find(key)) {
135 return nullptr;
136 }
137
138 const auto object_region_capacity = static_cast<uint32_t>(LIVE_ARENA_CAPACITY - sizeof(LiveArenaHeader));
139
140 const uint32_t aligned_bump = align_up(g_live_arena_bump, alignment);
141
142 if (aligned_bump + size > object_region_capacity) {
143 return nullptr;
144 }
145
146 const uint32_t idx = hdr->entry_count;
147 auto& entry = hdr->entries[idx];
148 std::strncpy(entry.key, key, LIVE_ARENA_KEY_MAX - 1);
149 entry.key[LIVE_ARENA_KEY_MAX - 1] = '\0';
150 entry.offset = aligned_bump;
151 entry.size = size;
152 entry.occupied = true;
153
154 g_live_arena_bump = aligned_bump + size;
155 ++hdr->entry_count;
156
157 return live_arena_object_region() + aligned_bump;
158 }
Range size
constexpr std::size_t LIVE_ARENA_KEY_MAX
Maximum length of a live arena key, including null terminator.
Definition LiveArena.hpp:21
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:83
unsigned char * live_arena_object_region() noexcept
Returns a pointer to the object region (immediately after the header).
Definition LiveArena.hpp:91

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: