Debian Codegraph @

Source/Utilities/Memory/CNewAllocationMemoryPoolProvider.cpp

raw
1 /*
2 * Copyright (C) 2013-2015, 2019 by the Konclude Developer Team.
3 *
4 * This file is part of the reasoning system Konclude.
5 * For details and support, see <http://konclude.com/>.
6 *
7 * Konclude is free software: you can redistribute it and/or modify
8 * it under the terms of version 3 of the GNU Lesser General Public
9 * License (LGPLv3) as published by the Free Software Foundation.
10 *
11 * Konclude is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU (Lesser) General Public License for more details.
15 *
16 * You should have received a copy of the GNU (Lesser) General Public
17 * License along with Konclude. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #include "CNewAllocationMemoryPoolProvider.h"
22
23
24 namespace Konclude {
25
26 namespace Utilities {
27
28 namespace Memory {
29
30
31 CNewAllocationMemoryPoolProvider::CNewAllocationMemoryPoolProvider(cint64 defaultPoolSize) {
32 mDefaultPoolSize = defaultPoolSize;
33 mStatAllocatedPoolSize = 0;
34 mStatAllocatedPoolCount = 0;
35 mStatReleasedPoolSize = 0;
36 mStatReleasedPoolCount = 0;
37 mStatDiffPoolSize = 0;
38 mStatDiffPoolCount = 0;
39 }
40
41 CNewAllocationMemoryPoolProvider::~CNewAllocationMemoryPoolProvider() {
42 }
43
44
45 CMemoryPool* CNewAllocationMemoryPoolProvider::acquireMemoryPoolConsiderated(cint64 minPoolSize) {
46 return acquireMemoryPool(minPoolSize);
47 }
48
49
50 CMemoryPool* CNewAllocationMemoryPoolProvider::acquireMemoryPool(cint64 minPoolSize) {
51 CMemoryPool* memoryPool = new CMemoryPool();
52 if (!memoryPool) {
53 // not enough memory even for the log message
54 //LOG(CATASTROPHIC,"::Konclude::Utilities::NewAllocationMemoryPoolProvider",logTr("Memory allocation failed."),this);
55 }
56 cint64 memoryBlockSize = qMax(mDefaultPoolSize,minPoolSize) + 8;
57 char* memoryBlock = new char[memoryBlockSize];
58 if (!memoryBlock) {
59 LOG(CATASTROPHIC,"::Konclude::Utilities::NewAllocationMemoryPoolProvider",logTr("Memory allocation failed."),this);
60 }
61 mStatAllocatedPoolSize += memoryBlockSize;
62 mStatDiffPoolSize += memoryBlockSize;
63 ++mStatAllocatedPoolCount;
64 ++mStatDiffPoolCount;
65 memoryPool->setMemoryBlockData(memoryBlock,memoryBlockSize);
66 return memoryPool;
67 }
68
69
70 CMemoryPoolProvider* CNewAllocationMemoryPoolProvider::releaseMemoryPool(CMemoryPool* memoryPool) {
71 while (memoryPool) {
72 CMemoryPool* tmpMemoryPool = memoryPool;
73 memoryPool = memoryPool->getNext();
74 mStatReleasedPoolSize += tmpMemoryPool->getMemoryBlockSize();
75 mStatDiffPoolSize -= tmpMemoryPool->getMemoryBlockSize();
76 ++mStatReleasedPoolCount;
77 char* memoryBlock = tmpMemoryPool->getMemoryBlockData();
78 delete [] memoryBlock;
79 delete tmpMemoryPool;
80 }
81 return this;
82 }
83
84
85 cint64 CNewAllocationMemoryPoolProvider::getAllocatedReleaseDifferencePoolCount() {
86 return mStatDiffPoolCount;
87 }
88
89 cint64 CNewAllocationMemoryPoolProvider::getAllocatedReleaseDifferencePoolSize() {
90 return mStatDiffPoolSize;
91 }
92
93
94
95
96 }; // end namespace Memory
97
98 }; // end namespace Utilities
99
100 }; // end namespace Konclude
101