Debian Codegraph @

visa/iga/IGALibrary/MemManager/Arena.cpp

raw
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 #ifdef COLLECT_ALLOCATION_STATS
12 int numAllocations = 0;
13 int numMallocCalls = 0;
14 int totalAllocSize = 0;
15 int totalMallocSize = 0;
16 int numMemManagers = 0;
17 int maxArenaLength = 0;
18 #endif
19 using namespace iga;
20 void *ArenaHeader::AllocSpace(size_t size) {
21 assert(WordAlign(size_t(_nextByte)) == size_t(_nextByte));
22 void *allocSpace = _nextByte;
23
24 if (size) {
25 size = WordAlign(size);
26
27 if (_nextByte + size <= _lastByte) {
28 _nextByte += size;
29 } else {
30 allocSpace = 0;
31 }
32 } else {
33 allocSpace = 0;
34 }
35
36 return allocSpace;
37 }
38
39 void ArenaManager::FreeArenas() {
40 while (_arenas) {
41 unsigned char *killed = (unsigned char *)_arenas;
42 _arenas = _arenas->_nextArena;
43 delete[] killed;
44 }
45
46 _arenas = 0;
47 }