docs: Fix memory module documentation discrepancies
- Add missing PoolAllocator class overview with methods table - Add missing LinearAllocator class overview with methods table - Add missing ProxyAllocator class overview with methods table - Fix PoolAllocator::Allocate example code and comments - Clarify ProxyAllocator::Free totalFreed calculation behavior - Fix CreateLinearAllocator complexity from O(size) to O(1) - Add note about Reallocate thread safety in ProxyAllocator
This commit is contained in:
@@ -1,4 +1,42 @@
|
||||
# PoolAllocator::PoolAllocator / ~PoolAllocator
|
||||
# PoolAllocator
|
||||
|
||||
**命名空间**: `XCEngine::Memory`
|
||||
|
||||
**类型**: `class`
|
||||
|
||||
**描述**: 内存池分配器,预分配固定大小的内存块池。
|
||||
|
||||
## 概述
|
||||
|
||||
`PoolAllocator` 是一种高效固定块分配器,适合需要频繁分配和释放相同大小对象的场景,如对象池、粒子系统等。它预分配 `poolSize` 个大小为 `blockSize` 字节的内存块,通过空闲链表管理分配和回收。
|
||||
|
||||
## 公共方法
|
||||
|
||||
### 生命周期
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `PoolAllocator` | 构造内存池分配器 |
|
||||
| `~PoolAllocator` | 析构函数,释放整个内存池 |
|
||||
|
||||
### 内存操作
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `Allocate` | 分配一个内存块 |
|
||||
| `Free` | 释放内存块回空闲链表 |
|
||||
| `Reallocate` | 不支持(始终返回 nullptr) |
|
||||
|
||||
### 查询方法
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `Contains` | 检查指针是否属于此池 |
|
||||
| `GetBlockSize` | 获取块大小 |
|
||||
| `GetFreeBlockCount` | 获取空闲块数量 |
|
||||
| `GetTotalBlockCount` | 获取总块数 |
|
||||
|
||||
## 构造函数
|
||||
|
||||
```cpp
|
||||
PoolAllocator(size_t blockSize, size_t poolSize, size_t alignment = 8);
|
||||
@@ -16,6 +54,8 @@ PoolAllocator(size_t blockSize, size_t poolSize, size_t alignment = 8);
|
||||
|
||||
**复杂度:** O(n),需要预分配所有块
|
||||
|
||||
**注意:** `Reallocate` 方法始终返回 `nullptr`,此分配器不支持重新分配。
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
@@ -41,4 +81,5 @@ pool.Free(block);
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [PoolAllocator 总览](pool-allocator.md) - 返回类总览
|
||||
- [Memory 模块总览](../memory.md) - 返回模块总览
|
||||
- [IAllocator](../allocator/allocator.md) - 分配器接口
|
||||
|
||||
Reference in New Issue
Block a user