docs: update memory and threading API docs

This commit is contained in:
2026-03-20 02:35:24 +08:00
parent c5b17239ca
commit fd792b7df1
103 changed files with 2485 additions and 673 deletions

View File

@@ -0,0 +1,40 @@
# PoolAllocator::PoolAllocator
```cpp
PoolAllocator(size_t blockSize, size_t poolSize, size_t alignment = 8);
```
构造内存池分配器,预分配 `poolSize` 个大小为 `blockSize` 字节的内存块。内存块按 `alignment` 对齐(默认 8 字节)。内部维护一个空闲链表来管理分配。
**参数:**
- `blockSize` - 每个内存块的大小(字节)
- `poolSize` - 内存池中总块数
- `alignment` - 对齐要求,默认为 8 字节
**返回:**
**复杂度:** O(n),需要预分配所有块
**示例:**
```cpp
#include <XCEngine/Memory/PoolAllocator.h>
struct Particle {
float x, y, z;
float vx, vy, vz;
float life;
};
// 创建一个能容纳 1000 个 Particle 的内存池16 字节对齐
PoolAllocator pool(sizeof(Particle), 1000, alignof(Particle));
size_t blockSize = pool.GetBlockSize(); // sizeof(Particle)
size_t total = pool.GetTotalBlockCount(); // 1000
size_t free = pool.GetFreeBlockCount(); // 1000
```
## 相关文档
- [PoolAllocator 总览](pool-allocator.md) - 返回类总览
- [`~PoolAllocator`](~pool-allocator.md) - 析构函数