docs: fix naming conventions across threading, math, memory, core, and debug modules
threading/: - Rename 19 camelCase method files to hyphenated names - task-system: createtaskgroup→create-task-group, etc. - tasksystemconfig: enabletaskprofiling→enable-task-profiling, etc. - thread: getcurrentid→get-current-id, etc. - task: addref→add-ref, getid→get-id, etc. math/: - Rename underscore operator files to hyphenated - vector3: operator_add→operator-add, etc. - matrix4: gettranslation→get-translation, etc. - vector4: tovector3→to-vector3, constructor_vector3→constructor-vector3 - sphere: sphere_constructor→sphere-constructor, etc. memory/: - Remove duplicate memorymanager/ folder (kept manager/ which was correct) core/: - filewriter: Consolidate ctor-default.md and ctor-file.md into constructor.md - Rename dtor.md→destructor.md debug/: - filelogsink: Rename construct.md→constructor.md, ~filelogsink.md→destructor.md All overview pages updated with new file references.
This commit is contained in:
@@ -1,4 +1,43 @@
|
||||
# FileWriter::FileWriter (文件路径构造)
|
||||
# FileWriter::FileWriter
|
||||
|
||||
## 重载 1: 默认构造
|
||||
|
||||
```cpp
|
||||
FileWriter();
|
||||
```
|
||||
|
||||
默认构造 FileWriter 对象,不打开任何文件。
|
||||
|
||||
**描述**
|
||||
|
||||
创建 FileWriter 实例,m_file 初始化为 nullptr。可后续通过 Open 方法打开文件。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**线程安全:** ❌
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Core/FileWriter.h>
|
||||
|
||||
using namespace XCEngine::Core;
|
||||
|
||||
FileWriter writer;
|
||||
if (!writer.IsOpen()) {
|
||||
writer.Open("output.txt");
|
||||
writer.Write("Hello\n");
|
||||
writer.Close();
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 重载 2: 文件路径构造
|
||||
|
||||
```cpp
|
||||
FileWriter(const char* filePath, bool append = false);
|
||||
@@ -6,14 +45,12 @@ FileWriter(const char* filePath, bool append = false);
|
||||
|
||||
构造 FileWriter 对象并打开文件。
|
||||
|
||||
**描述**
|
||||
|
||||
创建 FileWriter 实例并尝试打开指定路径的文件。如果 append 为 true,则以追加模式打开;否则以覆盖模式打开。
|
||||
|
||||
**参数:**
|
||||
- `filePath` - 要打开的文件路径
|
||||
- `append` - 是否以追加模式打开,默认 false(覆盖模式)
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**线程安全:** ❌
|
||||
|
||||
**复杂度:** O(1)
|
||||
@@ -42,4 +79,3 @@ if (writer2.IsOpen()) {
|
||||
|
||||
- [FileWriter 总览](filewriter.md) - 返回类总览
|
||||
- [Open](Open.md) - 打开文件
|
||||
- [FileWriter()](ctor-default.md) - 默认构造
|
||||
@@ -1,36 +0,0 @@
|
||||
# FileWriter::FileWriter (默认构造)
|
||||
|
||||
```cpp
|
||||
FileWriter();
|
||||
```
|
||||
|
||||
默认构造 FileWriter 对象,不打开任何文件。
|
||||
|
||||
**描述**
|
||||
|
||||
创建 FileWriter 实例,m_file 初始化为 nullptr。可后续通过 Open 方法打开文件。
|
||||
|
||||
**线程安全:** ❌
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Core/FileWriter.h>
|
||||
|
||||
using namespace XCEngine::Core;
|
||||
|
||||
FileWriter writer;
|
||||
if (!writer.IsOpen()) {
|
||||
writer.Open("output.txt");
|
||||
writer.Write("Hello\n");
|
||||
writer.Close();
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [FileWriter 总览](filewriter.md) - 返回类总览
|
||||
- [Open](Open.md) - 打开文件
|
||||
- [FileWriter(filePath, append)](ctor-file.md) - 构造并打开文件
|
||||
@@ -10,6 +10,10 @@
|
||||
|
||||
销毁 FileWriter 实例,如果文件处于打开状态则自动调用 Close 关闭文件,释放 FILE* 资源。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**线程安全:** ❌
|
||||
|
||||
**复杂度:** O(1)
|
||||
@@ -16,9 +16,9 @@
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| [`FileWriter()`](ctor-default.md) | 默认构造(不打开文件) |
|
||||
| [`FileWriter(filePath, append)`](ctor-file.md) | 构造并打开文件 |
|
||||
| [`~FileWriter()`](dtor.md) | 析构函数,自动关闭文件 |
|
||||
| [`FileWriter()`](constructor.md) | 默认构造(不打开文件) |
|
||||
| [`FileWriter(filePath, append)`](constructor.md) | 构造并打开文件 |
|
||||
| [`~FileWriter()`](destructor.md) | 析构函数,自动关闭文件 |
|
||||
| [`Open`](Open.md) | 打开文件,append=true 时为追加模式 |
|
||||
| [`Close`](Close.md) | 关闭文件 |
|
||||
| [`IsOpen`](IsOpen.md) | 检查文件是否已打开 |
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| [`FileLogSink(const Containers::String& filePath)`](construct.md) | 打开指定路径的文件用于日志写入 |
|
||||
| [`~FileLogSink()`](~filelogsink.md) | 销毁实例并刷新缓冲区 |
|
||||
| [`FileLogSink(const Containers::String& filePath)`](constructor.md) | 打开指定路径的文件用于日志写入 |
|
||||
| [`~FileLogSink()`](destructor.md) | 销毁实例并刷新缓冲区 |
|
||||
| [`Log(const LogEntry& entry)`](log.md) | 将日志条目追加写入文件 |
|
||||
| [`Flush()`](flush.md) | 刷新文件缓冲区确保数据写入磁盘 |
|
||||
|
||||
|
||||
@@ -34,17 +34,17 @@
|
||||
| [`RotationX`](rotationx.md) | 创建绕 X 轴旋转矩阵 |
|
||||
| [`RotationY`](rotationy.md) | 创建绕 Y 轴旋转矩阵 |
|
||||
| [`RotationZ`](rotationz.md) | 创建绕 Z 轴旋转矩阵 |
|
||||
| [`operator*`](operator_mul.md) | 矩阵乘法 |
|
||||
| [`operator*`](operator-mul.md) | 矩阵乘法 |
|
||||
| [`MultiplyPoint`](multiplypoint.md) | 变换点(w=1) |
|
||||
| [`MultiplyVector`](multiplyvector.md) | 变换向量(w=0) |
|
||||
| [`Transpose`](transpose.md) | 转置矩阵 |
|
||||
| [`Inverse`](inverse.md) | 求逆矩阵 |
|
||||
| [`Determinant`](determinant.md) | 计算行列式 |
|
||||
| [`GetTranslation`](gettranslation.md) | 获取平移分量 |
|
||||
| [`GetRotation`](getrotation.md) | 获取旋转分量 |
|
||||
| [`GetScale`](getscale.md) | 获取缩放分量 |
|
||||
| [`GetTranslation`](get-translation.md) | 获取平移分量 |
|
||||
| [`GetRotation`](get-rotation.md) | 获取旋转分量 |
|
||||
| [`GetScale`](get-scale.md) | 获取缩放分量 |
|
||||
| [`Decompose`](decompose.md) | 分解矩阵为变换分量 |
|
||||
| [`operator[]`](operator_index.md) | 访问矩阵行数据 |
|
||||
| [`operator[]`](operator-index.md) | 访问矩阵行数据 |
|
||||
|
||||
## 使用示例
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
|
||||
| 方法 | 描述 | 线程安全 | 复杂度 |
|
||||
|------|------|----------|--------|
|
||||
| [`Sphere()`](sphere_default_constructor.md) | 默认构造,零初始化 | ✅ | O(1) |
|
||||
| [`Sphere(const Vector3&, float)`](sphere_constructor.md) | 从中心和半径构造球体 | ✅ | O(1) |
|
||||
| [`Sphere()`](sphere-default-constructor.md) | 默认构造,零初始化 | ✅ | O(1) |
|
||||
| [`Sphere(const Vector3&, float)`](sphere-constructor.md) | 从中心和半径构造球体 | ✅ | O(1) |
|
||||
| [`Contains`](contains.md) | 检测点是否在球体内 | ✅ | O(1) |
|
||||
| [`Intersects`](intersects.md) | 检测两个球体是否相交 | ✅ | O(1) |
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ Vector3 是 XCEngine 中用于表示三维向量的核心类型,支持常见
|
||||
| [`Lerp`](lerp.md) | 线性插值 |
|
||||
| [`MoveTowards`](movetowards.md) | 移向目标点 |
|
||||
| [`Project`](project.md) | 投影到法向量上 |
|
||||
| [`ProjectOnPlane`](projectonplane.md) | 投影到平面上 |
|
||||
| [`ProjectOnPlane`](project-on-plane.md) | 投影到平面上 |
|
||||
| [`Angle`](angle.md) | 计算两个向量之间的夹角 |
|
||||
| [`Reflect`](reflect.md) | 反射向量 |
|
||||
| [`Normalized`](normalized.md) | 返回归一化副本(实例方法) |
|
||||
@@ -49,12 +49,12 @@ Vector3 是 XCEngine 中用于表示三维向量的核心类型,支持常见
|
||||
|
||||
| 运算符 | 描述 |
|
||||
|--------|------|
|
||||
| [`+`](operator_add.md), [`-`](operator_sub.md) | 向量加减 |
|
||||
| [`*`](operator_mul.md), [`/`](operator_div.md) | 向量与标量或分量相乘/相除 |
|
||||
| [`+=`](operator_add_assign.md), [`-=`](operator_sub_assign.md) | 复合赋值运算符 |
|
||||
| [`*=`](operator_mul_assign.md), [`/=`](operator_div_assign.md) | 复合赋值运算符 |
|
||||
| [`[]`](./operator_index.md) | 下标访问 x, y, z 分量 |
|
||||
| [`==`](operator_eq.md), [`!=`](operator_neq.md) | 相等性比较 |
|
||||
| [`+`](operator-add.md), [`-`](operator-sub.md) | 向量加减 |
|
||||
| [`*`](operator-mul.md), [`/`](operator-div.md) | 向量与标量或分量相乘/相除 |
|
||||
| [`+=`](operator-add-assign.md), [`-=`](operator-sub-assign.md) | 复合赋值运算符 |
|
||||
| [`*=`](operator-mul-assign.md), [`/=`](operator-div-assign.md) | 复合赋值运算符 |
|
||||
| [`[]`](./operator-index.md) | 下标访问 x, y, z 分量 |
|
||||
| [`==`](operator-eq.md), [`!=`](operator-neq.md) | 相等性比较 |
|
||||
| [`* (Quaternion)`](quaternion-multiply.md) | 用四元数旋转向量 |
|
||||
|
||||
## 实例方法
|
||||
|
||||
@@ -29,14 +29,14 @@ Vector4 是四维向量结构体,常用于:
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| [`Vector4()`](constructor_default.md) | 默认构造函数,创建零向量 |
|
||||
| [`Vector4()`](constructor-default.md) | 默认构造函数,创建零向量 |
|
||||
| [`Vector4(x, y, z, w)`](constructor.md) | 从四个分量构造向量 |
|
||||
| [`Vector4(Vector3, w)`](constructor_vector3.md) | 从 Vector3 构造(w 默认 0) |
|
||||
| [`Vector4(Vector3, w)`](constructor-vector3.md) | 从 Vector3 构造(w 默认 0) |
|
||||
| [`Zero`](zero.md) | 返回零向量 (0, 0, 0, 0) |
|
||||
| [`One`](one.md) | 返回单位向量 (1, 1, 1, 1) |
|
||||
| [`Dot`](dot.md) | 计算两个向量的点积 |
|
||||
| [`Project`](project.md) | 将向量投影到法线向量上 |
|
||||
| [`ToVector3`](tovector3.md) | 转换为 Vector3 |
|
||||
| [`ToVector3`](to-vector3.md) | 转换为 Vector3 |
|
||||
| [`operator[]`](./operator-brackets.md) | 下标访问分量 |
|
||||
| [`operator+`](operator-add.md) | 向量加法 |
|
||||
| [`operator-`](operator-sub.md) | 向量减法 |
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
# MemoryManager::CreateLinearAllocator
|
||||
|
||||
```cpp
|
||||
std::unique_ptr<LinearAllocator> CreateLinearAllocator(size_t size);
|
||||
```
|
||||
|
||||
创建并返回一个新的 LinearAllocator 实例,使用系统分配器作为底层。返回的 `unique_ptr` 管理分配器生命周期。
|
||||
|
||||
**参数:**
|
||||
- `size` - 分配器缓冲区大小(字节)
|
||||
|
||||
**返回:** LinearAllocator 的 unique_ptr
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Memory/MemoryManager.h>
|
||||
|
||||
auto linear = MemoryManager::Get().CreateLinearAllocator(1024 * 1024);
|
||||
void* ptr = linear->Allocate(256);
|
||||
void* marker = linear->GetMarker();
|
||||
linear->Allocate(128);
|
||||
linear->SetMarker(marker);
|
||||
linear->Clear();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [MemoryManager 总览](memorymanager.md) - 返回类总览
|
||||
- [LinearAllocator](../linear-allocator/linear-allocator.md) - 线性分配器
|
||||
@@ -1,37 +0,0 @@
|
||||
# MemoryManager::CreatePoolAllocator
|
||||
|
||||
```cpp
|
||||
std::unique_ptr<PoolAllocator> CreatePoolAllocator(size_t blockSize, size_t count);
|
||||
```
|
||||
|
||||
创建并返回一个新的 PoolAllocator 实例,使用系统分配器作为底层。返回的 `unique_ptr` 管理分配器生命周期。
|
||||
|
||||
**参数:**
|
||||
- `blockSize` - 每个内存块的大小(字节)
|
||||
- `count` - 内存池中块的数量
|
||||
|
||||
**返回:** PoolAllocator 的 unique_ptr
|
||||
|
||||
**复杂度:** O(blockSize * count)(需要预分配所有块)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Memory/MemoryManager.h>
|
||||
|
||||
struct Particle {
|
||||
float x, y, z;
|
||||
float life;
|
||||
};
|
||||
|
||||
auto pool = MemoryManager::Get().CreatePoolAllocator(sizeof(Particle), 1000);
|
||||
void* block = pool->Allocate();
|
||||
auto* p = new (block) Particle{1.0f, 2.0f, 3.0f, 5.0f};
|
||||
p->~Particle();
|
||||
pool->Free(block);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [MemoryManager 总览](memorymanager.md) - 返回类总览
|
||||
- [PoolAllocator](../pool-allocator/pool-allocator.md) - 内存池分配器
|
||||
@@ -1,36 +0,0 @@
|
||||
# MemoryManager::CreateProxyAllocator
|
||||
|
||||
```cpp
|
||||
std::unique_ptr<ProxyAllocator> CreateProxyAllocator(const char* name);
|
||||
```
|
||||
|
||||
创建并返回一个新的 ProxyAllocator 实例,包装系统分配器并使用指定名称。返回的 `unique_ptr` 管理分配器生命周期。
|
||||
|
||||
**参数:**
|
||||
- `name` - 代理分配器的名称
|
||||
|
||||
**返回:** ProxyAllocator 的 unique_ptr
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Memory/MemoryManager.h>
|
||||
|
||||
auto proxy = MemoryManager::Get().CreateProxyAllocator("FrameData");
|
||||
void* ptr = proxy->Allocate(1024);
|
||||
void* ptr2 = proxy->Allocate(512);
|
||||
|
||||
const auto& stats = proxy->GetStats();
|
||||
printf("Peak: %zu bytes, Count: %zu\n",
|
||||
stats.peakAllocated, stats.allocationCount);
|
||||
|
||||
proxy->Free(ptr);
|
||||
proxy->Free(ptr2);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [MemoryManager 总览](memorymanager.md) - 返回类总览
|
||||
- [ProxyAllocator](../proxy-allocator/proxy-allocator.md) - 代理分配器
|
||||
@@ -1,31 +0,0 @@
|
||||
# MemoryManager::DumpMemoryLeaks
|
||||
|
||||
```cpp
|
||||
void DumpMemoryLeaks();
|
||||
```
|
||||
|
||||
输出当前未释放的内存分配信息。如果启用了内存跟踪,此方法会遍历所有记录并报告疑似泄漏的分配。应在程序退出前调用,以便发现资源泄漏。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(n)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Memory/MemoryManager.h>
|
||||
|
||||
MemoryManager::Get().Initialize();
|
||||
|
||||
// ... 程序运行 ...
|
||||
|
||||
// 程序退出前检查泄漏
|
||||
MemoryManager::Get().DumpMemoryLeaks();
|
||||
MemoryManager::Get().Shutdown();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [MemoryManager 总览](memorymanager.md) - 返回类总览
|
||||
@@ -1,37 +0,0 @@
|
||||
# MemoryManager::GenerateMemoryReport
|
||||
|
||||
```cpp
|
||||
void GenerateMemoryReport();
|
||||
```
|
||||
|
||||
生成并输出当前内存使用情况的详细报告。报告内容包括各分配器的统计信息、峰值使用量、分配次数等。应在启用内存跟踪后调用。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(n)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Memory/MemoryManager.h>
|
||||
|
||||
MemoryManager::Get().Initialize();
|
||||
|
||||
auto proxy = MemoryManager::Get().CreateProxyAllocator("GameFrame");
|
||||
proxy->Allocate(1024 * 1024);
|
||||
proxy->Allocate(512 * 1024);
|
||||
|
||||
// 生成内存报告
|
||||
MemoryManager::Get().GenerateMemoryReport();
|
||||
|
||||
proxy->Free(proxy->Allocate(256 * 1024));
|
||||
MemoryManager::Get().GenerateMemoryReport();
|
||||
|
||||
MemoryManager::Get().Shutdown();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [MemoryManager 总览](memorymanager.md) - 返回类总览
|
||||
@@ -1,39 +0,0 @@
|
||||
# MemoryManager::Get
|
||||
|
||||
```cpp
|
||||
static MemoryManager& Get();
|
||||
```
|
||||
|
||||
获取 MemoryManager 单例实例。如果尚未创建则内部构造。此方法是获取内存管理器实例的唯一途径。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** MemoryManager 单例引用
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Memory/MemoryManager.h>
|
||||
|
||||
// 获取单例
|
||||
MemoryManager& manager = MemoryManager::Get();
|
||||
|
||||
// 初始化
|
||||
manager.Initialize();
|
||||
|
||||
// 访问系统分配器
|
||||
IAllocator* sysAlloc = manager.GetSystemAllocator();
|
||||
|
||||
// 关闭
|
||||
manager.Shutdown();
|
||||
|
||||
// 多次调用返回同一实例
|
||||
MemoryManager& manager2 = MemoryManager::Get();
|
||||
// manager == manager2 为 true
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [MemoryManager 总览](memorymanager.md) - 返回类总览
|
||||
@@ -1,27 +0,0 @@
|
||||
# MemoryManager::GetSystemAllocator
|
||||
|
||||
```cpp
|
||||
IAllocator* GetSystemAllocator();
|
||||
```
|
||||
|
||||
获取系统默认分配器。该分配器使用标准 C 库的 `std::malloc` 和平台特定的对齐分配函数(如 Windows 的 `_aligned_malloc`)作为后端,适用于通用内存分配场景。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** 系统分配器指针
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Memory/MemoryManager.h>
|
||||
|
||||
IAllocator* sysAlloc = MemoryManager::Get().GetSystemAllocator();
|
||||
void* ptr = sysAlloc->Allocate(1024);
|
||||
sysAlloc->Free(ptr);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [MemoryManager 总览](memorymanager.md) - 返回类总览
|
||||
@@ -1,33 +0,0 @@
|
||||
# MemoryManager::Initialize
|
||||
|
||||
```cpp
|
||||
void Initialize();
|
||||
```
|
||||
|
||||
初始化内存管理器。创建系统默认分配器,设置内存跟踪标志。应在程序启动早期调用,且仅可调用一次。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(n)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Memory/MemoryManager.h>
|
||||
|
||||
int main() {
|
||||
// 程序启动时初始化
|
||||
MemoryManager::Get().Initialize();
|
||||
|
||||
// 使用内存系统...
|
||||
|
||||
MemoryManager::Get().Shutdown();
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [MemoryManager 总览](memorymanager.md) - 返回类总览
|
||||
@@ -1,85 +0,0 @@
|
||||
# MemoryManager
|
||||
|
||||
**命名空间**: `XCEngine::Memory`
|
||||
|
||||
**类型**: `class` (singleton)
|
||||
|
||||
**描述**: 全局内存管理器单例,提供系统分配器和各种专用分配器的创建与管理。
|
||||
|
||||
## 概述
|
||||
|
||||
`MemoryManager` 是 XCEngine 内存管理系统的核心单例。它负责维护系统分配器,提供分配器工厂方法,并支持内存泄漏检测和报告。
|
||||
|
||||
## 单例访问
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| [`Get`](get.md) | 获取单例实例 |
|
||||
|
||||
## 公共方法
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| [`Initialize`](initialize.md) | 初始化内存管理器 |
|
||||
| [`Shutdown`](shutdown.md) | 关闭内存管理器 |
|
||||
| [`GetSystemAllocator`](getsystemallocator.md) | 获取系统默认分配器 |
|
||||
| [`CreateLinearAllocator`](createlinearallocator.md) | 创建线性分配器 |
|
||||
| [`CreatePoolAllocator`](createpoolallocator.md) | 创建内存池分配器 |
|
||||
| [`CreateProxyAllocator`](createproxyallocator.md) | 创建代理分配器 |
|
||||
| [`SetTrackAllocations`](settrackallocations.md) | 设置是否跟踪分配 |
|
||||
| [`DumpMemoryLeaks`](dumpmemoryleaks.md) | 输出内存泄漏报告 |
|
||||
| [`GenerateMemoryReport`](generatememoryreport.md) | 生成内存使用报告 |
|
||||
|
||||
## 宏定义
|
||||
|
||||
### XE_ALLOC
|
||||
|
||||
```cpp
|
||||
#define XE_ALLOC(allocator, size, ...) allocator->Allocate(size, ##__VA_ARGS__)
|
||||
```
|
||||
|
||||
内存分配宏。
|
||||
|
||||
### XE_FREE
|
||||
|
||||
```cpp
|
||||
#define XE_FREE(allocator, ptr) allocator->Free(ptr)
|
||||
```
|
||||
|
||||
内存释放宏。
|
||||
|
||||
## 使用示例
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Memory/MemoryManager.h>
|
||||
|
||||
// 初始化
|
||||
MemoryManager::Get().Initialize();
|
||||
|
||||
// 获取系统分配器
|
||||
IAllocator* sysAlloc = MemoryManager::Get().GetSystemAllocator();
|
||||
|
||||
// 创建专用分配器
|
||||
auto linearAlloc = MemoryManager::Get().CreateLinearAllocator(1024 * 1024);
|
||||
auto poolAlloc = MemoryManager::Get().CreatePoolAllocator(sizeof(MyObject), 1000);
|
||||
auto proxyAlloc = MemoryManager::Get().CreateProxyAllocator("GameFrame");
|
||||
|
||||
// 使用宏分配
|
||||
void* ptr = XE_ALLOC(proxyAlloc, 256);
|
||||
XE_FREE(proxyAlloc, ptr);
|
||||
|
||||
// 跟踪内存
|
||||
MemoryManager::Get().SetTrackAllocations(true);
|
||||
MemoryManager::Get().GenerateMemoryReport();
|
||||
|
||||
// 关闭
|
||||
MemoryManager::Get().Shutdown();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Memory 模块总览](../memory.md) - 返回模块总览
|
||||
- [IAllocator](../allocator/allocator.md) - 分配器接口
|
||||
- [LinearAllocator](../linear-allocator/linear-allocator.md) - 线性分配器
|
||||
- [PoolAllocator](../pool-allocator/pool-allocator.md) - 内存池分配器
|
||||
- [ProxyAllocator](../proxy-allocator/proxy-allocator.md) - 代理分配器
|
||||
@@ -1,35 +0,0 @@
|
||||
# MemoryManager::SetTrackAllocations
|
||||
|
||||
```cpp
|
||||
void SetTrackAllocations(bool track);
|
||||
```
|
||||
|
||||
设置是否启用内存分配跟踪。启用后系统会记录所有分配操作,用于生成内存报告和泄漏检测。
|
||||
|
||||
**参数:**
|
||||
- `track` - true 启用跟踪,false 禁用跟踪
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Memory/MemoryManager.h>
|
||||
|
||||
MemoryManager::Get().Initialize();
|
||||
|
||||
// 禁用跟踪(提升性能)
|
||||
MemoryManager::Get().SetTrackAllocations(false);
|
||||
|
||||
// ... 大量内存操作 ...
|
||||
|
||||
// 重新启用跟踪进行分析
|
||||
MemoryManager::Get().SetTrackAllocations(true);
|
||||
MemoryManager::Get().GenerateMemoryReport();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [MemoryManager 总览](memorymanager.md) - 返回类总览
|
||||
@@ -1,35 +0,0 @@
|
||||
# MemoryManager::Shutdown
|
||||
|
||||
```cpp
|
||||
void Shutdown();
|
||||
```
|
||||
|
||||
关闭内存管理器。执行内存泄漏检测报告,释放系统分配器。应在程序退出前调用。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(n)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Memory/MemoryManager.h>
|
||||
|
||||
int main() {
|
||||
MemoryManager::Get().Initialize();
|
||||
|
||||
// ... 游戏主循环 ...
|
||||
|
||||
// 程序退出前关闭
|
||||
MemoryManager::Get().DumpMemoryLeaks();
|
||||
MemoryManager::Get().Shutdown();
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [MemoryManager 总览](memorymanager.md) - 返回类总览
|
||||
@@ -30,10 +30,10 @@
|
||||
| [`Shutdown`](shutdown.md) | 关闭任务系统 |
|
||||
| [`Submit(unique_ptr)`](submit.md) | 提交任务对象 |
|
||||
| [`Submit(callback)`](submit.md) | 提交 lambda 任务 |
|
||||
| [`CreateTaskGroup`](createtaskgroup.md) | 创建任务组 |
|
||||
| [`DestroyTaskGroup`](destroytaskgroup.md) | 销毁任务组 |
|
||||
| [`CreateTaskGroup`](create-task-group.md) | 创建任务组 |
|
||||
| [`DestroyTaskGroup`](destroy-task-group.md) | 销毁任务组 |
|
||||
| [`Wait`](wait.md) | 等待指定任务完成(当前为空实现) |
|
||||
| [`GetWorkerThreadCount`](getworkerthreadcount.md) | 获取工作线程数量 |
|
||||
| [`GetWorkerThreadCount`](get-worker-thread-count.md) | 获取工作线程数量 |
|
||||
| [`ParallelFor`](parallelfor.md) | 并行执行 for 循环 |
|
||||
| [`RunOnMainThread`](runonmainthread.md) | 将任务提交到主线程执行 |
|
||||
| [`Update`](update.md) | 在主线程中处理主线程队列 |
|
||||
|
||||
@@ -43,15 +43,15 @@
|
||||
|------|------|
|
||||
| `virtual ~ITask()` | 虚析构函数 |
|
||||
| [`Execute`](execute.md) | 任务执行逻辑(纯虚) |
|
||||
| [`OnComplete`](oncomplete.md) | 任务完成回调(可重写) |
|
||||
| [`OnCancel`](oncancel.md) | 任务取消回调(可重写) |
|
||||
| [`GetPriority`](getpriority.md) | 获取优先级 |
|
||||
| [`GetStatus`](getstatus.md) | 获取状态 |
|
||||
| [`GetId`](getid.md) | 获取任务 ID |
|
||||
| [`SetId`](setid.md) | 设置任务 ID |
|
||||
| [`SetPriority`](setpriority.md) | 设置优先级 |
|
||||
| [`SetStatus`](setstatus.md) | 设置状态 |
|
||||
| [`AddRef`](addref.md) | 增加引用计数 |
|
||||
| [`OnComplete`](on-complete.md) | 任务完成回调(可重写) |
|
||||
| [`OnCancel`](on-cancel.md) | 任务取消回调(可重写) |
|
||||
| [`GetPriority`](get-priority.md) | 获取优先级 |
|
||||
| [`GetStatus`](get-status.md) | 获取状态 |
|
||||
| [`GetId`](get-id.md) | 获取任务 ID |
|
||||
| [`SetId`](set-id.md) | 设置任务 ID |
|
||||
| [`SetPriority`](set-priority.md) | 设置优先级 |
|
||||
| [`SetStatus`](set-status.md) | 设置状态 |
|
||||
| [`AddRef`](add-ref.md) | 增加引用计数 |
|
||||
| [`Release`](release.md) | 减少引用计数(引用归零时自动 delete) |
|
||||
|
||||
## 受保护方法
|
||||
|
||||
@@ -12,11 +12,11 @@
|
||||
|
||||
| 成员 | 类型 | 描述 | 默认值 |
|
||||
|------|------|------|--------|
|
||||
| [`workerThreadCount`](workerthreadcount.md) | `uint32_t` | 工作线程数量(0=自动检测 CPU 核心数) | 0 |
|
||||
| [`enableTaskProfiling`](enabletaskprofiling.md) | `bool` | 启用任务性能分析(当前未使用) | true |
|
||||
| [`stealTasks`](stealtasks.md) | `bool` | 启用工作窃取(当前未实现) | true |
|
||||
| [`maxTaskQueueSize`](maxtaskqueuesize.md) | `uint32_t` | 最大任务队列大小(当前未强制限制) | 1024 |
|
||||
| [`threadStackSize`](threadstacksize.md) | `uint32_t` | 线程栈大小(当前未使用,0=系统默认) | 0 |
|
||||
| [`workerThreadCount`](worker-thread-count.md) | `uint32_t` | 工作线程数量(0=自动检测 CPU 核心数) | 0 |
|
||||
| [`enableTaskProfiling`](enable-task-profiling.md) | `bool` | 启用任务性能分析(当前未使用) | true |
|
||||
| [`stealTasks`](steal-tasks.md) | `bool` | 启用工作窃取(当前未实现) | true |
|
||||
| [`maxTaskQueueSize`](max-task-queue-size.md) | `uint32_t` | 最大任务队列大小(当前未强制限制) | 1024 |
|
||||
| [`threadStackSize`](thread-stack-size.md) | `uint32_t` | 线程栈大小(当前未使用,0=系统默认) | 0 |
|
||||
|
||||
## 使用示例
|
||||
|
||||
|
||||
@@ -29,9 +29,9 @@
|
||||
| [`Start`](start.md) | 启动线程,执行传入的函数 |
|
||||
| [`Join`](join.md) | 等待线程结束 |
|
||||
| [`Detach`](detach.md) | 分离线程,使其独立运行 |
|
||||
| [`GetId`](getid.md) | 获取线程 ID |
|
||||
| [`GetName`](getname.md) | 获取线程名称 |
|
||||
| [`GetCurrentId`](getcurrentid.md) | 获取当前线程 ID |
|
||||
| [`GetId`](get-id.md) | 获取线程 ID |
|
||||
| [`GetName`](get-name.md) | 获取线程名称 |
|
||||
| [`GetCurrentId`](get-current-id.md) | 获取当前线程 ID |
|
||||
| [`Sleep`](sleep.md) | 线程休眠指定毫秒数 |
|
||||
| [`Yield`](yield.md) | 让出当前线程的时间片 |
|
||||
|
||||
|
||||
Reference in New Issue
Block a user