| 65 | } |
| 66 | |
| 67 | void StackAllocator::Free(void* ptr) { |
| 68 | current_allocation_count--; |
| 69 | // AssertMainThread(); |
| 70 | #ifdef DEBUG_DISABLE_STACK_ALLOCATOR |
| 71 | OG_FREE(ptr); |
| 72 | #else // DEBUG_DISABLE_STACK_ALLOCATOR |
| 73 | if (stack_blocks) { |
| 74 | --stack_blocks; |
| 75 | LOG_ASSERT(ptr == (void*)((uintptr_t)mem + stack_block_pts[stack_blocks])); |
| 76 | if (ptr != (void*)((uintptr_t)mem + stack_block_pts[stack_blocks])) { |
| 77 | LOGE << "Called fre on something that isn't at the top of the stack" << endl; |
| 78 | LOGE << "Stacktrace:" << endl |
| 79 | << GenerateStacktrace() << endl; |
| 80 | } |
| 81 | |
| 82 | } else { |
| 83 | #ifndef NO_ERR |
| 84 | FatalError("Memory stack underflow", "Calling Free() on StackMemoryBlock with no stack elements"); |
| 85 | #endif |
| 86 | } |
| 87 | #endif // DEBUG_DISABLE_STACK_ALLOCATOR |
| 88 | } |
| 89 | |
| 90 | uintptr_t StackAllocator::TopBlockSize() { |
| 91 | switch (stack_blocks) { |