2026-03-26 16:45:24 +08:00
|
|
|
# MemoryManager::CreatePoolAllocator
|
|
|
|
|
|
2026-03-26 18:02:29 +08:00
|
|
|
创建一个池分配器。
|
2026-03-26 16:45:24 +08:00
|
|
|
|
|
|
|
|
```cpp
|
|
|
|
|
std::unique_ptr<PoolAllocator> CreatePoolAllocator(size_t blockSize, size_t count);
|
|
|
|
|
```
|
|
|
|
|
|
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
|
|
|
|
|
return std::make_unique<PoolAllocator>(blockSize, count);
|
|
|
|
|
```
|
2026-03-26 16:45:24 +08:00
|
|
|
|
2026-03-26 18:02:29 +08:00
|
|
|
它不会使用 `m_systemAllocator`,因此即使没有调用 [Initialize](Initialize.md) 也可以工作。
|
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
|
|
|
- `blockSize` - 单个逻辑 block 大小。
|
|
|
|
|
- `count` - block 数量。
|
|
|
|
|
|
|
|
|
|
## 返回值
|
|
|
|
|
|
|
|
|
|
- `std::unique_ptr<PoolAllocator>` - 由调用方拥有的池分配器。
|
|
|
|
|
|
|
|
|
|
## 注意事项
|
|
|
|
|
|
|
|
|
|
- 这个工厂同样只是创建对象,不会集中托管其生命周期。
|
|
|
|
|
- 参数不会在 `MemoryManager` 层做额外校验,`PoolAllocator` 自身当前也缺少防御式检查。
|
2026-03-26 16:45:24 +08:00
|
|
|
|
|
|
|
|
## 相关文档
|
|
|
|
|
|
2026-03-26 18:02:29 +08:00
|
|
|
- [返回类型总览](MemoryManager.md)
|
|
|
|
|
- [Initialize](Initialize.md)
|