MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / Alloc

Method Alloc

Source/Memory/stack_allocator.cpp:42–65  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40using std::endl;
41
42void* StackAllocator::Alloc(size_t requested_size) {
43 current_allocation_count++;
44 frame_allocation_count++;
45 // AssertMainThread();
46#ifdef DEBUG_DISABLE_STACK_ALLOCATOR
47 return OG_MALLOC(requested_size);
48#else // DEBUG_DISABLE_STACK_ALLOCATOR
49 if (stack_block_pts[stack_blocks] + requested_size < size && stack_blocks < kMaxBlocks - 2) {
50 ++stack_blocks;
51 stack_block_pts[stack_blocks] = stack_block_pts[stack_blocks - 1] + requested_size;
52 void* ptr = (void*)((uintptr_t)mem + stack_block_pts[stack_blocks - 1]);
53 return ptr;
54 } else {
55 if (stack_block_pts[stack_blocks] + requested_size >= size) {
56 LOGF << "Unable to stack allocate memory size:" << requested_size << ". Out of memory." << endl;
57 } else {
58 LOGF << "Unable to stack allocate memory size:" << requested_size << ". Out of blocks." << endl;
59 }
60
61 LOGF << GenerateStacktrace() << endl;
62 return NULL;
63 }
64#endif // DEBUG_DISABLE_STACK_ALLOCATOR
65}
66
67void StackAllocator::Free(void* ptr) {
68 current_allocation_count--;

Callers 15

CreateMethod · 0.45
LoadCubeMapMipmapsHDRMethod · 0.45
LoadMethod · 0.45
RequestUploadMethod · 0.45
SteamworksUGCMethod · 0.45
DrawMethod · 0.45
StackLoadTextFunction · 0.45
test<1>Method · 0.45
test<2>Method · 0.45
test<3>Method · 0.45
test<4>Method · 0.45

Calls 1

GenerateStacktraceFunction · 0.85

Tested by 5

test<1>Method · 0.36
test<2>Method · 0.36
test<3>Method · 0.36
test<4>Method · 0.36
test<5>Method · 0.36