MCPcopy Create free account
hub / github.com/Norbyte/bg3se / Allocate

Method Allocate

BG3Extender/GameDefinitions/EntitySystem.cpp:142–163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

140
141
142void* FrameAllocator::Allocate(uint16_t size)
143{
144 auto realSize = (uint16_t)(size + 63) & 0xFFC0u;
145
146 auto curPage = CurrentPage;
147 auto offset = (uint64_t)InterlockedExchangeAdd64(&curPage->Offset, realSize);
148 while (offset + realSize > PageSize) {
149
150 EnterCriticalSection(&CS);
151 if (curPage == CurrentPage) {
152 auto page = AllocPage();
153 page->Offset = 0x40;
154 CurrentPage = page;
155 }
156 LeaveCriticalSection(&CS);
157
158 curPage = CurrentPage;
159 offset = (uint64_t)InterlockedExchangeAdd64(&curPage->Offset, realSize);
160 }
161
162 return (uint8_t*)curPage + offset;
163}
164
165FrameAllocator::FrameBuffer* FrameAllocator::AllocPage()
166{

Callers 4

PrepareAddComponentMethod · 0.45
CreateComponentRawMethod · 0.45
allocMethod · 0.45
allocArrayMethod · 0.45

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected