Files
XCEngine/docs/api/memory/proxy-allocator/free.md
ssdfasd 82cf147817 docs: 修正 API 文档准确性 (第四轮检查)
修复问题:
- containers: HashMap 实现描述修正
- debug: XE_LOG 宏参数顺序修正
- memory: ProxyAllocator 统计示例修正, PoolAllocator allocate size 检查描述
- resources: ResourceManager 缺失 UnloadGroup 方法
- rhi: D3D12 格式枚举名称修正, Texture Format 枚举补全, ResourceStates 补充
- threading: TaskGroup GetProgress/Wait/Cancel 实现限制说明
2026-03-19 00:43:16 +08:00

41 lines
1.2 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.
# ProxyAllocator::Free
```cpp
void Free(void* ptr) override;
```
释放内存并记录统计。调用转发到底层分配器,同时更新统计信息:递增 `totalFreed`(累加当前分配计数),并递减 `allocationCount`。由于 ProxyAllocator 不记录单独释放的字节数,`totalFreed` 累加的是 `allocationCount` 而非实际字节大小。
**参数:**
- `ptr` - 指向要释放的内存块
**返回:**
**复杂度:** O(1)(底层释放 + 统计更新)
**示例:**
```cpp
#include <XCEngine/Memory/MemoryManager.h>
#include <XCEngine/Memory/ProxyAllocator.h>
IAllocator* sysAlloc = MemoryManager::Get().GetSystemAllocator();
ProxyAllocator proxy(sysAlloc, "TrackedAlloc");
void* p1 = proxy.Allocate(512);
void* p2 = proxy.Allocate(256);
proxy.Free(p1);
proxy.Free(p2);
const auto& stats = proxy.GetStats();
// totalFreed 累加了每次释放时的 allocationCount次数非字节
// allocationCount 最终为 0
printf("Total allocated: %zu bytes, Freed count: %zu, Current count: %zu\n",
stats.totalAllocated, stats.totalFreed, stats.allocationCount);
```
## 相关文档
- [ProxyAllocator 总览](proxy-allocator.md) - 返回类总览