Files
XCEngine/docs/api/memory/allocator/get-total-freed.md
ssdfasd a9f882f233 docs: 修正 API 文档准确性 (第二轮检查)
修复的问题:
- math: 修复 Quaternion::Normalize 链接错误
- containers: HashMap 迭代器示例使用不存在的 cbegin/cend,删除冗余构造函数声明
- core: RefCounted 析构函数访问级别修正 (protected)
- debug: LogLevelToString 示例返回值大小写修正
- memory: 修正 LinearAllocator::Reallocate 返回 nullptr,ProxyAllocator 统计描述,头文件路径 IAllocator.h -> Allocator.h
- resources: Texture::Create mipLevels 参数描述修正
- rhi: 修复多处链接错误,新增缺失的方法文档
- threading: TaskSystem 配置项未实现状态标注,Wait 方法空实现标注
2026-03-19 00:31:14 +08:00

51 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# IAllocator::GetTotalFreed
```cpp
virtual size_t GetTotalFreed() const = 0;
```
返回此分配器自创建以来累计释放的字节总数。部分分配器(如 LinearAllocator可能始终返回 0因为它们不跟踪单个释放操作。
**参数:**
**返回:** 累计已释放的字节数
**复杂度:** O(1)
**示例:**
```cpp
#include <XCEngine/Memory/Allocator.h>
class MyAllocator : public IAllocator {
size_t m_freed = 0;
public:
void* Allocate(size_t size, size_t alignment = 0) override { return ::operator new(size); }
void Free(void* ptr) override {
if (ptr) {
size_t size = 256; // 需要外部记录
::operator delete(ptr);
m_freed += size;
}
}
void* Reallocate(void* ptr, size_t newSize) override { /* ... */ }
size_t GetTotalAllocated() const override { return 0; }
size_t GetTotalFreed() const override { return m_freed; }
size_t GetPeakAllocated() const override { return 0; }
size_t GetAllocationCount() const override { return 0; }
const char* GetName() const override { return "MyAllocator"; }
};
MyAllocator alloc;
void* ptr = alloc.Allocate(128);
alloc.Free(ptr);
size_t freed = alloc.GetTotalFreed(); // 返回 128
```
## 相关文档
- [IAllocator 总览](allocator.md) - 返回类总览