- Containers: String, Array, HashMap 容器实现及测试 - Memory: Allocator, LinearAllocator, PoolAllocator, ProxyAllocator, MemoryManager 实现及测试 - Threading: Mutex, SpinLock, ReadWriteLock, Thread, Task, TaskSystem 实现及测试 - 修复Windows平台兼容性: _aligned_malloc, std::hash特化 - 修复构建错误和测试用例问题
42 lines
1.1 KiB
C++
42 lines
1.1 KiB
C++
#pragma once
|
|
|
|
#include "Allocator.h"
|
|
#include "Threading/Mutex.h"
|
|
|
|
namespace XCEngine {
|
|
namespace Memory {
|
|
|
|
class ProxyAllocator : public IAllocator {
|
|
public:
|
|
ProxyAllocator(IAllocator* underlying, const char* name);
|
|
|
|
void* Allocate(size_t size, size_t alignment = 0) override;
|
|
void Free(void* ptr) override;
|
|
void* Reallocate(void* ptr, size_t newSize) override;
|
|
|
|
size_t GetTotalAllocated() const override { return m_stats.totalAllocated; }
|
|
size_t GetTotalFreed() const override { return m_stats.totalFreed; }
|
|
size_t GetPeakAllocated() const override { return m_stats.peakAllocated; }
|
|
size_t GetAllocationCount() const override { return m_stats.allocationCount; }
|
|
|
|
struct Stats {
|
|
size_t totalAllocated = 0;
|
|
size_t totalFreed = 0;
|
|
size_t peakAllocated = 0;
|
|
size_t allocationCount = 0;
|
|
size_t memoryOverhead = 0;
|
|
};
|
|
const Stats& GetStats() const;
|
|
|
|
const char* GetName() const override { return m_name; }
|
|
|
|
private:
|
|
IAllocator* m_underlying = nullptr;
|
|
const char* m_name = nullptr;
|
|
Stats m_stats;
|
|
Threading::Mutex m_mutex;
|
|
};
|
|
|
|
} // namespace Memory
|
|
} // namespace XCEngine
|