2026-03-26 16:45:24 +08:00
|
|
|
|
# ProxyAllocator::Free
|
|
|
|
|
|
|
2026-03-26 18:02:29 +08:00
|
|
|
|
通过底层分配器释放内存,并更新代理统计。
|
2026-03-26 16:45:24 +08:00
|
|
|
|
|
|
|
|
|
|
```cpp
|
|
|
|
|
|
void Free(void* ptr) override;
|
|
|
|
|
|
```
|
|
|
|
|
|
|
2026-03-26 18:02:29 +08:00
|
|
|
|
## 行为说明
|
2026-03-26 16:45:24 +08:00
|
|
|
|
|
2026-03-26 18:02:29 +08:00
|
|
|
|
当前实现会先加锁,然后执行:
|
2026-03-26 16:45:24 +08:00
|
|
|
|
|
2026-03-26 18:02:29 +08:00
|
|
|
|
1. 调用 `m_underlying->Free(ptr)`。
|
|
|
|
|
|
2. 执行 `m_stats.totalFreed += m_stats.allocationCount`。
|
|
|
|
|
|
3. 执行 `m_stats.allocationCount--`。
|
2026-03-26 16:45:24 +08:00
|
|
|
|
|
2026-03-26 18:02:29 +08:00
|
|
|
|
## 参数
|
2026-03-26 16:45:24 +08:00
|
|
|
|
|
2026-03-26 18:02:29 +08:00
|
|
|
|
- `ptr` - 要释放的指针。
|
2026-03-26 16:45:24 +08:00
|
|
|
|
|
2026-03-26 18:02:29 +08:00
|
|
|
|
## 返回值
|
|
|
|
|
|
|
|
|
|
|
|
- 无。
|
|
|
|
|
|
|
|
|
|
|
|
## 当前实现限制
|
|
|
|
|
|
|
|
|
|
|
|
- `totalFreed` 增加的是“当前 allocation count”,不是被释放块的真实字节数。
|
|
|
|
|
|
- 如果 `allocationCount` 当前为 `0`,执行 `m_stats.allocationCount--` 会发生无符号下溢。
|
|
|
|
|
|
- `ptr` 是否允许为 `nullptr`,取决于底层分配器;代理层没有额外保护。
|
|
|
|
|
|
- 如果 `m_underlying == nullptr`,当前实现会直接解引用空指针。
|
2026-03-26 16:45:24 +08:00
|
|
|
|
|
|
|
|
|
|
## 相关文档
|
|
|
|
|
|
|
2026-03-26 18:02:29 +08:00
|
|
|
|
- [返回类型总览](ProxyAllocator.md)
|
|
|
|
|
|
- [Allocate](Allocate.md)
|
|
|
|
|
|
- [GetTotalFreed](GetTotalFreed.md)
|