refactor: reorganize docs into plan/ and add skills/
This commit is contained in:
72
docs/api/memory/memory-overview.md
Normal file
72
docs/api/memory/memory-overview.md
Normal file
@@ -0,0 +1,72 @@
|
||||
# Memory 模块概览
|
||||
|
||||
**命名空间**: `XCEngine::Memory`
|
||||
|
||||
**类型**: `module`
|
||||
|
||||
**描述**: XCEngine 的内存管理模块,提供多种内存分配器实现。
|
||||
|
||||
## 概述
|
||||
|
||||
Memory 模块提供了一套完整的内存管理解决方案,包括基础分配器接口和各种专用分配器实现。
|
||||
|
||||
## 模块内容
|
||||
|
||||
### 分配器接口
|
||||
|
||||
| 组件 | 文件 | 描述 |
|
||||
|------|------|------|
|
||||
| [IAllocator](./memory-allocator.md) | `Allocator.h` | 内存分配器抽象接口 |
|
||||
|
||||
### 分配器实现
|
||||
|
||||
| 组件 | 文件 | 描述 |
|
||||
|------|------|------|
|
||||
| [LinearAllocator](./memory-linear-allocator.md) | `LinearAllocator.h` | 线性分配器,适合帧分配 |
|
||||
| [PoolAllocator](./memory-pool-allocator.md) | `PoolAllocator.h` | 内存池分配器,适合固定大小对象 |
|
||||
| [ProxyAllocator](./memory-proxy-allocator.md) | `ProxyAllocator.h` | 代理分配器,用于统计和跟踪 |
|
||||
|
||||
### 管理器
|
||||
|
||||
| 组件 | 文件 | 描述 |
|
||||
|------|------|------|
|
||||
| [MemoryManager](./memory-manager.md) | `MemoryManager.h` | 全局内存管理器 |
|
||||
|
||||
## 分配器类型对比
|
||||
|
||||
| 分配器 | 适用场景 | 特点 |
|
||||
|--------|----------|------|
|
||||
| `IAllocator` | 基类接口 | 定义标准分配协议 |
|
||||
| `LinearAllocator` | 帧分配、临时对象 | 快速分配,只支持按顺序释放 |
|
||||
| `PoolAllocator` | 同尺寸对象池 | 高效分配,消除碎片 |
|
||||
| `ProxyAllocator` | 调试和统计 | 记录分配信息,跟踪内存使用 |
|
||||
|
||||
## 宏定义
|
||||
|
||||
| 宏 | 描述 |
|
||||
|----|------|
|
||||
| `XE_ALLOC(allocator, size, ...)` | 内存分配宏 |
|
||||
| `XE_FREE(allocator, ptr)` | 内存释放宏 |
|
||||
|
||||
## 使用示例
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Memory/MemoryManager.h>
|
||||
|
||||
// 获取系统分配器
|
||||
IAllocator* sysAlloc = MemoryManager::Get().GetSystemAllocator();
|
||||
|
||||
// 创建线性分配器
|
||||
auto linearAlloc = MemoryManager::Get().CreateLinearAllocator(1024 * 1024);
|
||||
|
||||
// 使用代理分配器跟踪统计
|
||||
auto proxyAlloc = MemoryManager::Get().CreateProxyAllocator("FrameData");
|
||||
|
||||
// 分配内存
|
||||
void* ptr = XE_ALLOC(linearAlloc, 1024);
|
||||
XE_FREE(linearAlloc, ptr);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Containers 模块](../containers/container-overview.md) - 使用分配器的容器
|
||||
Reference in New Issue
Block a user