Apply formating to all files. CLeanup
This commit is contained in:
parent
43e374f269
commit
744c01c5d0
928 changed files with 14515 additions and 21480 deletions
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
#include "Utils.hpp"
|
||||
|
||||
#include "HeapAllocatorGlobal.hpp"
|
||||
#include "HeapAllocator.hpp"
|
||||
#include "ChunkAllocator.hpp"
|
||||
#include "HeapAllocator.hpp"
|
||||
#include "HeapAllocatorGlobal.hpp"
|
||||
#include "PoolAllocator.hpp"
|
||||
|
||||
namespace tp {
|
||||
|
|
@ -13,15 +13,15 @@ namespace tp {
|
|||
|
||||
void* operator new(std::size_t aSize);
|
||||
void* operator new[](std::size_t aSize);
|
||||
void operator delete(void* aPtr) noexcept;
|
||||
void operator delete[](void* aPtr) noexcept;
|
||||
void operator delete(void* aPtr) noexcept;
|
||||
void operator delete[](void* aPtr) noexcept;
|
||||
|
||||
void* operator new(std::size_t aSize, tp::HeapAlloc& aAlloc);
|
||||
void* operator new[](std::size_t aSize, tp::HeapAlloc& aAlloc);
|
||||
void operator delete(void* aPtr, tp::HeapAlloc& aAlloc);
|
||||
void operator delete[](void* aPtr, tp::HeapAlloc& aAlloc);
|
||||
void operator delete(void* aPtr, tp::HeapAlloc& aAlloc);
|
||||
void operator delete[](void* aPtr, tp::HeapAlloc& aAlloc);
|
||||
|
||||
void* operator new(std::size_t aSize, tp::HeapAllocGlobal& aAlloc);
|
||||
void* operator new[](std::size_t aSize, tp::HeapAllocGlobal& aAlloc);
|
||||
void operator delete(void* aPtr, tp::HeapAllocGlobal& aAlloc);
|
||||
void operator delete[](void* aPtr, tp::HeapAllocGlobal& aAlloc);
|
||||
void operator delete(void* aPtr, tp::HeapAllocGlobal& aAlloc);
|
||||
void operator delete[](void* aPtr, tp::HeapAllocGlobal& aAlloc);
|
||||
|
|
@ -14,8 +14,8 @@
|
|||
* 2) updating list entry to that block.
|
||||
*/
|
||||
|
||||
#include "HeapAllocatorGlobal.hpp"
|
||||
#include "Environment.hpp"
|
||||
#include "HeapAllocatorGlobal.hpp"
|
||||
#include "PrivateConfig.hpp"
|
||||
|
||||
namespace tp {
|
||||
|
|
@ -23,7 +23,7 @@ namespace tp {
|
|||
// Chunk Allocator
|
||||
// Constant time allocations and de-allocations in any order.
|
||||
// Memory blocks are fixed in size and number of blocks can not exceed given parameter.
|
||||
template<typename tType, ualni tNumBlocks>
|
||||
template <typename tType, ualni tNumBlocks>
|
||||
class ChunkAlloc {
|
||||
|
||||
enum : ualni {
|
||||
|
|
@ -76,24 +76,24 @@ namespace tp {
|
|||
|
||||
// 2) Find free block and update next free block
|
||||
auto data = mNextBlock;
|
||||
mNextBlock = (ualni*)(*data);
|
||||
mNextBlock = (ualni*) (*data);
|
||||
mNumFreeBlocks--;
|
||||
|
||||
#ifdef MEM_DEBUG
|
||||
// 3) Fill Wrap and offset data
|
||||
auto wrap_top = data;
|
||||
auto wrap_bottom = data + WRAP_SIZE_ALN + dataSize();
|
||||
#ifdef MEM_DEBUG
|
||||
// 3) Fill Wrap and offset data
|
||||
auto wrap_top = data;
|
||||
auto wrap_bottom = data + WRAP_SIZE_ALN + dataSize();
|
||||
|
||||
memSetVal(wrap_top, WRAP_SIZE, WRAP_VAL);
|
||||
memSetVal(wrap_bottom, WRAP_SIZE, WRAP_VAL);
|
||||
memSetVal(wrap_top, WRAP_SIZE, WRAP_VAL);
|
||||
memSetVal(wrap_bottom, WRAP_SIZE, WRAP_VAL);
|
||||
|
||||
// 4) Clear data
|
||||
#ifdef MEM_CLEAR_ON_ALLOC
|
||||
memSetVal(data + WRAP_SIZE_ALN, dataSize() * ALIGNED_SIZE, CLEAR_ALLOC_VAL);
|
||||
#endif
|
||||
// 4) Clear data
|
||||
#ifdef MEM_CLEAR_ON_ALLOC
|
||||
memSetVal(data + WRAP_SIZE_ALN, dataSize() * ALIGNED_SIZE, CLEAR_ALLOC_VAL);
|
||||
#endif
|
||||
|
||||
data += WRAP_SIZE_ALN;
|
||||
#endif
|
||||
data += WRAP_SIZE_ALN;
|
||||
#endif
|
||||
|
||||
return data;
|
||||
}
|
||||
|
|
@ -101,26 +101,26 @@ namespace tp {
|
|||
void deallocate(void* aPtr) {
|
||||
DEBUG_ASSERT(aPtr >= mBuff && aPtr < mBuff + tNumBlocks * blockSize())
|
||||
|
||||
auto block = (ualni*)aPtr;
|
||||
auto block = (ualni*) aPtr;
|
||||
|
||||
#ifdef MEM_DEBUG
|
||||
// 3) Check Wrap and offset data
|
||||
auto wrap_bottom = block + dataSize();
|
||||
auto wrap_top = block - WRAP_SIZE_ALN;
|
||||
block = wrap_top;
|
||||
#ifdef MEM_DEBUG
|
||||
// 3) Check Wrap and offset data
|
||||
auto wrap_bottom = block + dataSize();
|
||||
auto wrap_top = block - WRAP_SIZE_ALN;
|
||||
block = wrap_top;
|
||||
|
||||
// 3) Check the wrap
|
||||
ASSERT(!memCompareVal(wrap_top, WRAP_SIZE, WRAP_VAL) && "Allocated Block Wrap Corrupted!")
|
||||
ASSERT(!memCompareVal(wrap_bottom, WRAP_SIZE, WRAP_VAL) && "Allocated Block Wrap Corrupted!")
|
||||
// 3) Check the wrap
|
||||
ASSERT(!memCompareVal(wrap_top, WRAP_SIZE, WRAP_VAL) && "Allocated Block Wrap Corrupted!")
|
||||
ASSERT(!memCompareVal(wrap_bottom, WRAP_SIZE, WRAP_VAL) && "Allocated Block Wrap Corrupted!")
|
||||
|
||||
// 4) Clear data
|
||||
#ifdef MEM_CLEAR_ON_ALLOC
|
||||
memSetVal(block, blockSize() * ALIGNED_SIZE, CLEAR_DEALLOC_VAL);
|
||||
#endif
|
||||
// 4) Clear data
|
||||
#ifdef MEM_CLEAR_ON_ALLOC
|
||||
memSetVal(block, blockSize() * ALIGNED_SIZE, CLEAR_DEALLOC_VAL);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
(*block) = (ualni)mNextBlock;
|
||||
(*block) = (ualni) mNextBlock;
|
||||
mNextBlock = block;
|
||||
mNumFreeBlocks++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,14 +21,14 @@ namespace tp {
|
|||
|
||||
// Pool Allocator
|
||||
// Overcomes chunk allocator fixed number of max allocations
|
||||
template<typename tType, ualni tNumBlocks>
|
||||
template <typename tType, ualni tNumBlocks>
|
||||
class PoolAlloc {
|
||||
|
||||
typedef ChunkAlloc<tType, tNumBlocks> Chunk;
|
||||
|
||||
struct Chunks {
|
||||
|
||||
void add(Chunk* aChunk){
|
||||
void add(Chunk* aChunk) {
|
||||
|
||||
if (!mBuff) {
|
||||
mLen = 16;
|
||||
|
|
@ -57,7 +57,7 @@ namespace tp {
|
|||
}
|
||||
}
|
||||
|
||||
void remove(Chunk** del_address){
|
||||
void remove(Chunk** del_address) {
|
||||
if (mUsedLen == 1) {
|
||||
mLen = 0;
|
||||
mUsedLen = 0;
|
||||
|
|
@ -74,18 +74,16 @@ namespace tp {
|
|||
mUsedLen--;
|
||||
|
||||
// check for buff low usage
|
||||
if ((halnf)mUsedLen / (halnf)mLen < 0.25f) {
|
||||
if ((halnf) mUsedLen / (halnf) mLen < 0.25f) {
|
||||
auto prevBuff = mBuff;
|
||||
mBuff = (Chunk**)HeapAllocGlobal::allocate(sizeof(Chunk*) * mLen / 2);
|
||||
mBuff = (Chunk**) HeapAllocGlobal::allocate(sizeof(Chunk*) * mLen / 2);
|
||||
memCopy(mBuff, prevBuff, sizeof(Chunk*) * mUsedLen);
|
||||
mLen /= 2;
|
||||
HeapAllocGlobal::deallocate(prevBuff);
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] Chunk** find(void* aPtr) {
|
||||
return findUtil(mBuff, mBuff + mUsedLen, aPtr) - 1;
|
||||
}
|
||||
[[nodiscard]] Chunk** find(void* aPtr) { return findUtil(mBuff, mBuff + mUsedLen, aPtr) - 1; }
|
||||
|
||||
[[nodiscard]] Chunk* findNotFull() const {
|
||||
for (ualni idx = 0; idx < mUsedLen; idx++) {
|
||||
|
|
@ -137,9 +135,9 @@ namespace tp {
|
|||
auto chunk = mChunks.find(aPtr);
|
||||
(*chunk)->deallocate(aPtr);
|
||||
if ((*chunk)->isEmpty()) {
|
||||
if (mFreeChunk == *chunk) mFreeChunk = nullptr;
|
||||
HeapAllocGlobal::deallocate(*chunk);
|
||||
mChunks.remove(chunk);
|
||||
if (mFreeChunk == *chunk) mFreeChunk = nullptr;
|
||||
HeapAllocGlobal::deallocate(*chunk);
|
||||
mChunks.remove(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -153,7 +151,7 @@ namespace tp {
|
|||
if (i > j) {
|
||||
ASSERT(mChunks.mBuff[i] > mChunks.mBuff[j])
|
||||
} else if (i < j) {
|
||||
ASSERT(mChunks.mBuff[i] < mChunks.mBuff[j])
|
||||
ASSERT(mChunks.mBuff[i] < mChunks.mBuff[j])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue