Files
XCEngine/docs/api/memory/allocator/get-total-freed.md

49 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 {
public:
void* Allocate(size_t size, size_t alignment = 0) override { return ::operator new(size); }
void Free(void* ptr) override {
if (ptr) {
// size 需要分配器内部记录或通过其他机制获取
::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 0; }
const char* GetName() const override { return "MyAllocator"; }
};
MyAllocator alloc;
void* ptr = alloc.Allocate(128);
alloc.Free(ptr);
size_t freed = alloc.GetTotalFreed(); // 返回 0示例未统计
```
## 相关文档
- [IAllocator 总览](allocator.md) - 返回类总览