Files
XCSDD/docs/api/memory/allocator/get-total-freed.md
ssdfasd 58a83f445a fix: improve doc link navigation and tree display
- 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
2026-03-19 12:44:08 +08:00

51 lines
1.3 KiB
Markdown
Raw Permalink 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) - 返回类总览