- Fix link resolution with proper relative/absolute path handling - Improve link styling with underline decoration - Hide leaf nodes from tree, only show directories - Fix log file path for packaged app
1.2 KiB
1.2 KiB
IAllocator::GetAllocationCount
virtual size_t GetAllocationCount() const = 0;
返回当前处于已分配状态(未释放)的内存块数量。此方法用于监控活跃分配的数量。
参数: 无
返回: 当前已分配块的数量
复杂度: O(1)
示例:
#include <XCEngine/Memory/Allocator.h>
class MyAllocator : public IAllocator {
size_t m_count = 0;
public:
void* Allocate(size_t size, size_t alignment = 0) override {
++m_count;
return ::operator new(size);
}
void Free(void* ptr) override {
if (ptr) {
--m_count;
::operator delete(ptr);
}
}
void* Reallocate(void* ptr, size_t newSize) override { /* ... */ }
size_t GetTotalAllocated() const override { return 0; }
size_t GetTotalFreed() const override { return 0; }
size_t GetPeakAllocated() const override { return 0; }
size_t GetAllocationCount() const override { return m_count; }
const char* GetName() const override { return "MyAllocator"; }
};
MyAllocator alloc;
alloc.Allocate(64);
alloc.Allocate(128);
size_t count = alloc.GetAllocationCount(); // 返回 2
相关文档
- IAllocator 总览 - 返回类总览