| 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 "CReallocationIncreasingMemoryPoolProvider.h" |
| 22 |
|
| 23 |
|
| 24 |
namespace Konclude { |
| 25 |
|
| 26 |
namespace Utilities { |
| 27 |
|
| 28 |
namespace Memory { |
| 29 |
|
| 30 |
|
| 31 |
CReallocationIncreasingMemoryPoolProvider::CReallocationIncreasingMemoryPoolProvider(CMemoryAllocationManager* reallocatingMemMan, cint64 defaultPoolSize, cint64 maxPoolSize, double increasingFactor) : CConsiderateMemoryPoolProvider() { |
| 32 |
mReallocatingMemMan = reallocatingMemMan; |
| 33 |
mDefaultPoolSize = defaultPoolSize; |
| 34 |
mStatAllocatedPoolSize = 0; |
| 35 |
mStatAllocatedPoolCount = 0; |
| 36 |
mStatReleasedPoolSize = 0; |
| 37 |
mStatReleasedPoolCount = 0; |
| 38 |
mStatDiffPoolSize = 0; |
| 39 |
mStatDiffPoolCount = 0; |
| 40 |
mMaxPoolSize = maxPoolSize; |
| 41 |
mIncreasingFactor = increasingFactor; |
| 42 |
} |
| 43 |
|
| 44 |
CReallocationIncreasingMemoryPoolProvider::~CReallocationIncreasingMemoryPoolProvider() { |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
CMemoryPool* CReallocationIncreasingMemoryPoolProvider::acquireMemoryPoolConsiderated(cint64 minPoolSize) { |
| 50 |
return acquireMemoryPool(minPoolSize); |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
CMemoryPool* CReallocationIncreasingMemoryPoolProvider::acquireMemoryPool(cint64 minPoolSize) { |
| 55 |
mDefaultPoolSize *= mIncreasingFactor; |
| 56 |
mDefaultPoolSize = qMin(mDefaultPoolSize, mMaxPoolSize); |
| 57 |
CMemoryPool* memoryPool = CObjectAllocator<CMemoryPool>::allocateAndConstruct(mReallocatingMemMan); |
| 58 |
if (!memoryPool) { |
| 59 |
// not enough memory even for the log message |
| 60 |
//LOG(CATASTROPHIC,"::Konclude::Utilities::NewAllocationMemoryPoolProvider",logTr("Memory allocation failed."),this); |
| 61 |
} |
| 62 |
cint64 memoryBlockSize = qMax(mDefaultPoolSize, minPoolSize); |
| 63 |
char* memoryBlock = CObjectAllocator<char>::allocateAndConstructArray(mReallocatingMemMan, memoryBlockSize); |
| 64 |
if (!memoryBlock) { |
| 65 |
LOG(CATASTROPHIC, "::Konclude::Utilities::NewAllocationMemoryPoolProvider", logTr("Memory allocation failed."), this); |
| 66 |
} |
| 67 |
mStatAllocatedPoolSize += memoryBlockSize; |
| 68 |
mStatDiffPoolSize += memoryBlockSize; |
| 69 |
++mStatAllocatedPoolCount; |
| 70 |
++mStatDiffPoolCount; |
| 71 |
memoryPool->setMemoryBlockData(memoryBlock, memoryBlockSize); |
| 72 |
return memoryPool; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
CMemoryPoolProvider* CReallocationIncreasingMemoryPoolProvider::releaseMemoryPool(CMemoryPool* memoryPool) { |
| 77 |
return this; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
cint64 CReallocationIncreasingMemoryPoolProvider::getAllocatedReleaseDifferencePoolCount() { |
| 82 |
return mStatDiffPoolCount; |
| 83 |
} |
| 84 |
|
| 85 |
cint64 CReallocationIncreasingMemoryPoolProvider::getAllocatedReleaseDifferencePoolSize() { |
| 86 |
return mStatDiffPoolSize; |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
}; // end namespace Memory |
| 91 |
|
| 92 |
}; // end namespace Utilities |
| 93 |
|
| 94 |
}; // end namespace Konclude |
| 95 |
|