- audio: 更新 audio-system 方法文档 - components: 新增 audio-listener/audio-source 组件方法文档,新增 remove-component 方法 - core: 更新 filewriter, types 文档 - math: 更新 box 方法文档 - memory: 更新 proxy-allocator 文档 - resources: 更新 loader 和 texture 文档 - rhi: 更新 opengl 设备、shader、swap-chain 文档 - threading: 更新 mutex 和 task-system 文档
78 lines
2.2 KiB
Markdown
78 lines
2.2 KiB
Markdown
# Memory 模块概览
|
|
|
|
**命名空间**: `XCEngine::Memory`
|
|
|
|
**类型**: `module`
|
|
|
|
**头文件**: `XCEngine/Memory/MemoryManager.h`
|
|
|
|
**描述**: XCEngine 的内存管理模块,提供多种内存分配器实现。
|
|
|
|
## 概述
|
|
|
|
Memory 模块提供了一套完整的内存管理解决方案,包括基础分配器接口和各种专用分配器实现。
|
|
|
|
## 模块内容
|
|
|
|
### 分配器接口
|
|
|
|
| 组件 | 文件 | 描述 |
|
|
|------|------|------|
|
|
| [IAllocator](allocator/allocator.md) | `Allocator.h` | 内存分配器抽象接口 |
|
|
|
|
### 分配器实现
|
|
|
|
| 组件 | 文件 | 描述 |
|
|
|------|------|------|
|
|
| [LinearAllocator](linear-allocator/linear-allocator.md) | `LinearAllocator.h` | 线性分配器,适合帧分配 |
|
|
| [PoolAllocator](pool-allocator/pool-allocator.md) | `PoolAllocator.h` | 内存池分配器,适合固定大小对象 |
|
|
| [ProxyAllocator](proxy-allocator/proxy-allocator.md) | `ProxyAllocator.h` | 代理分配器,用于统计和跟踪 |
|
|
|
|
### 管理器
|
|
|
|
| 组件 | 文件 | 描述 |
|
|
|------|------|------|
|
|
| [MemoryManager](manager/manager.md) | `MemoryManager.h` | 全局内存管理器 |
|
|
|
|
## 分配器类型对比
|
|
|
|
| 分配器 | 适用场景 | 特点 |
|
|
|--------|----------|------|
|
|
| `IAllocator` | 基类接口 | 定义标准分配协议 |
|
|
| `LinearAllocator` | 帧分配、临时对象 | 快速分配,只支持按顺序释放 |
|
|
| `PoolAllocator` | 同尺寸对象池 | 高效分配,消除碎片 |
|
|
| `ProxyAllocator` | 调试和统计 | 记录分配信息,跟踪内存使用 |
|
|
|
|
## 宏定义
|
|
|
|
| 宏 | 描述 |
|
|
|----|------|
|
|
| `XE_ALLOC(allocator, size, ...)` | 内存分配宏 |
|
|
| `XE_FREE(allocator, ptr)` | 内存释放宏 |
|
|
|
|
## 使用示例
|
|
|
|
```cpp
|
|
#include <XCEngine/Memory/MemoryManager.h>
|
|
|
|
// 初始化内存管理器
|
|
MemoryManager::Get().Initialize();
|
|
|
|
// 获取系统分配器
|
|
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/containers.md) - 使用分配器的容器
|