mirror of
https://github.com/thunderbrewhq/common.git
synced 2025-12-12 03:02:29 +00:00
Compare commits
No commits in common. "739adccafdb7af46afd47fc3ad8cc77a34e56dda" and "c57f882da2f12f379c857160a007f596a3f60b3c" have entirely different histories.
739adccafd
...
c57f882da2
4 changed files with 0 additions and 133 deletions
|
|
@ -2,7 +2,6 @@ file(GLOB COMMON_SOURCES
|
||||||
"*.cpp"
|
"*.cpp"
|
||||||
"datamgr/*.cpp"
|
"datamgr/*.cpp"
|
||||||
"datastore/*.cpp"
|
"datastore/*.cpp"
|
||||||
"memory/*.cpp"
|
|
||||||
"mempool/*.cpp"
|
"mempool/*.cpp"
|
||||||
"objectalloc/*.cpp"
|
"objectalloc/*.cpp"
|
||||||
"processor/*.cpp"
|
"processor/*.cpp"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
#ifndef COMMON_DATA_ALLOCATOR_HPP
|
|
||||||
#define COMMON_DATA_ALLOCATOR_HPP
|
|
||||||
|
|
||||||
#include "common/memory/CDataAllocator.hpp"
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,94 +0,0 @@
|
||||||
#include "common/memory/CDataAllocator.hpp"
|
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
#include <storm/Error.hpp>
|
|
||||||
#include <bc/Memory.hpp>
|
|
||||||
|
|
||||||
CDataAllocator::CDataAllocator(uint32_t bytesPerData, uint32_t dataPerBlock) {
|
|
||||||
this->m_bytesPerData = std::max(bytesPerData, uint32_t(sizeof(Data)));
|
|
||||||
this->m_dataPerBlock = std::max(dataPerBlock, uint32_t(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
CDataAllocator::~CDataAllocator() {
|
|
||||||
}
|
|
||||||
|
|
||||||
void CDataAllocator::Clear(const char* fileName, int32_t lineNumber) {
|
|
||||||
if (this->m_dataUsed) {
|
|
||||||
if (!fileName) {
|
|
||||||
fileName == __FILE__;
|
|
||||||
lineNumber = __LINE__;
|
|
||||||
}
|
|
||||||
|
|
||||||
SErrDisplayErrorFmt(
|
|
||||||
0x8510007E,
|
|
||||||
fileName,
|
|
||||||
lineNumber,
|
|
||||||
1,
|
|
||||||
1,
|
|
||||||
"CDataAllocator@0x%08x: leaked %u: %s(%d) [%u][%u]",
|
|
||||||
this,
|
|
||||||
this->m_dataUsed,
|
|
||||||
fileName,
|
|
||||||
lineNumber,
|
|
||||||
this->m_dataPerBlock,
|
|
||||||
this->m_bytesPerData);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (this->m_blockList) {
|
|
||||||
auto block = this->m_blockList;
|
|
||||||
this->m_blockList = block->m_next;
|
|
||||||
SMemFree(block);
|
|
||||||
}
|
|
||||||
|
|
||||||
this->m_dataUsed = 0;
|
|
||||||
this->m_dataList = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
CDataAllocator::Data* CDataAllocator::GetData(int32_t zero, const char* fileName, int32_t lineNumber) {
|
|
||||||
if (this->m_dataPerBlock == 1) {
|
|
||||||
fileName = nullptr;
|
|
||||||
lineNumber = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this->m_dataList) {
|
|
||||||
if (!fileName) {
|
|
||||||
fileName = __FILE__;
|
|
||||||
lineNumber = __LINE__;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto memory = static_cast<char*>(SMemAlloc(
|
|
||||||
this->m_dataPerBlock * this->m_bytesPerData + sizeof(Block),
|
|
||||||
fileName,
|
|
||||||
lineNumber,
|
|
||||||
0));
|
|
||||||
Block* block = reinterpret_cast<Block*>(memory);
|
|
||||||
Data* data = reinterpret_cast<Data*>(memory + sizeof(Block*));
|
|
||||||
|
|
||||||
this->m_dataList = data;
|
|
||||||
for (uint32_t i = 0; i < this->m_dataPerBlock - 1; ++i) {
|
|
||||||
auto next = reinterpret_cast<char*>(data) + this->m_bytesPerData;
|
|
||||||
data->m_next = reinterpret_cast<Data*>(next);
|
|
||||||
data = data->m_next;
|
|
||||||
}
|
|
||||||
data->m_next = 0;
|
|
||||||
block->m_next = this->m_blockList;
|
|
||||||
this->m_blockList = block;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto data = this->m_dataList;
|
|
||||||
this->m_dataList = data->m_next;
|
|
||||||
if (zero) {
|
|
||||||
memset(data, 0, this->m_bytesPerData);
|
|
||||||
}
|
|
||||||
this->m_dataUsed++;
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CDataAllocator::PutData(void* data, const char* fileName, int32_t lineNumber) {
|
|
||||||
STORM_ASSERT(this->m_dataUsed > 0);
|
|
||||||
auto d = reinterpret_cast<Data*>(data);
|
|
||||||
d->m_next = this->m_dataList;
|
|
||||||
this->m_dataUsed--;
|
|
||||||
this->m_dataList = d;
|
|
||||||
}
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
#ifndef COMMON_MEMORY_C_DATA_ALLOCATOR_HPP
|
|
||||||
#define COMMON_MEMORY_C_DATA_ALLOCATOR_HPP
|
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
class CDataAllocator {
|
|
||||||
public:
|
|
||||||
// Sub-types
|
|
||||||
struct Block {
|
|
||||||
Block* m_next;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Data {
|
|
||||||
Data* m_next;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Member functions
|
|
||||||
CDataAllocator(uint32_t bytesPerData, uint32_t dataPerBlock);
|
|
||||||
~CDataAllocator();
|
|
||||||
void Clear(const char* fileName, int32_t lineNumber);
|
|
||||||
Data* GetData(int32_t zero, const char* fileName, int32_t lineNumber);
|
|
||||||
void PutData(void* data, const char* fileName, int32_t lineNumber);
|
|
||||||
|
|
||||||
// Member variables
|
|
||||||
uint32_t m_bytesPerData = sizeof(Data);
|
|
||||||
uint32_t m_dataPerBlock = 1;
|
|
||||||
uint32_t m_dataUsed = 0;
|
|
||||||
Block* m_blockList = nullptr;
|
|
||||||
Data* m_dataList = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue