| 40 | using std::endl; |
| 41 | |
| 42 | void* 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 | |
| 67 | void StackAllocator::Free(void* ptr) { |
| 68 | current_allocation_count--; |