2026-03-26 16:45:24 +08:00
|
|
|
# PoolAllocator::GetAllocationCount
|
|
|
|
|
|
2026-03-26 18:02:29 +08:00
|
|
|
查询当前已分配 block 数量。
|
2026-03-26 16:45:24 +08:00
|
|
|
|
|
|
|
|
```cpp
|
|
|
|
|
size_t GetAllocationCount() const 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
|
|
|
```cpp
|
|
|
|
|
m_totalBlocks - m_freeBlocks
|
|
|
|
|
```
|
2026-03-26 16:45:24 +08:00
|
|
|
|
2026-03-26 18:02:29 +08:00
|
|
|
这反映的是“当前在用 block 数”,不是累计分配次数。
|
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
|
|
|
- `size_t` - 当前在用 block 数。
|
|
|
|
|
|
|
|
|
|
## 注意事项
|
|
|
|
|
|
|
|
|
|
- 这个值依赖 [Free](Free.md) 正确维护 `m_freeBlocks`。
|
|
|
|
|
- 如果发生重复释放或错误释放,`m_freeBlocks` 可能超过 `m_totalBlocks`,此处会出现无符号下溢并返回失真的大数值。
|
2026-03-26 16:45:24 +08:00
|
|
|
|
|
|
|
|
## 相关文档
|
|
|
|
|
|
2026-03-26 18:02:29 +08:00
|
|
|
- [返回类型总览](PoolAllocator.md)
|
|
|
|
|
- [GetFreeBlockCount](GetFreeBlockCount.md)
|