1 /*========================== begin_copyright_notice ============================ 2 3 Copyright (C) 2017-2021 Intel Corporation 4 5 SPDX-License-Identifier: MIT 6 7 ============================= end_copyright_notice ===========================*/ 8 9 #include "Arena.hpp" 10 11 12 #ifdef COLLECT_ALLOCATION_STATS 13 int numAllocations = 0; 14 int numMallocCalls = 0; 15 int totalAllocSize = 0; 16 int totalMallocSize = 0; 17 int numMemManagers = 0; 18 int maxArenaLength = 0; 19 #endif 20 using namespace iga; AllocSpace(size_t size)21void *ArenaHeader::AllocSpace(size_t size) 22 { 23 assert(WordAlign (size_t(_nextByte)) == size_t(_nextByte)); 24 void *allocSpace = _nextByte; 25 26 if (size) 27 { 28 size = WordAlign(size); 29 30 if (_nextByte + size <= _lastByte) { 31 _nextByte += size; 32 } else { 33 allocSpace = 0; 34 } 35 } 36 else 37 { 38 allocSpace = 0; 39 } 40 41 return allocSpace; 42 } 43 FreeArenas()44void ArenaManager::FreeArenas() 45 { 46 while (_arenas) { 47 unsigned char* killed = (unsigned char*)_arenas; 48 _arenas = _arenas->_nextArena; 49 delete [] killed; 50 } 51 52 _arenas = 0; 53 } 54