docs: 重构 API 文档结构并修正源码准确性
- 重组文档目录结构: 每个模块的概述页移动到模块子目录 - 重命名 index.md 为 main.md - 修正所有模块文档中的错误: - math: FromEuler→FromEulerAngles, TransformDirection 包含缩放, Box 是 OBB, Color::ToRGBA 格式 - containers: 新增 operator==/!= 文档, 补充 std::hash DJB 算法细节 - core: 修复 types 链接错误 - debug: LogLevelToString 返回大写, timestamp 是秒, Profiler 空实现标注, Windows API vs ANSI - memory: 修复头文件路径, malloc vs operator new, 新增方法文档 - resources: 修复 Shader/Texture 链接错误 - threading: TaskSystem::Wait 空实现标注, ReadWriteLock 重入描述, LambdaTask 链接 - 验证: fix_links.py 确认 0 个断裂引用
This commit is contained in:
41
docs/api/memory/linear-allocator/allocate.md
Normal file
41
docs/api/memory/linear-allocator/allocate.md
Normal file
@@ -0,0 +1,41 @@
|
||||
# LinearAllocator::Allocate
|
||||
|
||||
```cpp
|
||||
void* Allocate(size_t size, size_t alignment = 8) override;
|
||||
```
|
||||
|
||||
在缓冲区的当前位置顺序分配内存。每次分配都会将内部偏移量向前推进(对齐后)。如果剩余空间不足,则分配失败返回 `nullptr`。默认对齐值为 8 字节。
|
||||
|
||||
**参数:**
|
||||
- `size` - 请求的字节数
|
||||
- `alignment` - 内存对齐要求,默认为 8 字节
|
||||
|
||||
**返回:** 分配成功返回已对齐的指针,失败返回 `nullptr`
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Memory/LinearAllocator.h>
|
||||
|
||||
LinearAllocator allocator(1024);
|
||||
|
||||
// 分配 256 字节(8 字节对齐)
|
||||
void* ptr1 = allocator.Allocate(256);
|
||||
|
||||
// 分配 128 字节(16 字节对齐)
|
||||
void* ptr2 = allocator.Allocate(128, 16);
|
||||
|
||||
// 分配 64 字节(默认 8 字节对齐)
|
||||
void* ptr3 = allocator.Allocate(64);
|
||||
|
||||
// 检查是否成功
|
||||
if (!ptr1) {
|
||||
// 分配失败,缓冲区已满
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [LinearAllocator 总览](linear-allocator.md) - 返回类总览
|
||||
37
docs/api/memory/linear-allocator/clear.md
Normal file
37
docs/api/memory/linear-allocator/clear.md
Normal file
@@ -0,0 +1,37 @@
|
||||
# LinearAllocator::Clear
|
||||
|
||||
```cpp
|
||||
void Clear();
|
||||
```
|
||||
|
||||
清空分配器,将内部偏移量重置为 0,所有已分配的内存被视为已释放。下一次 `Allocate` 将从缓冲区起始位置开始。此方法不实际释放或修改底层内存,适合作为帧分配器使用,每帧开始时调用 Clear 重置。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Memory/LinearAllocator.h>
|
||||
|
||||
LinearAllocator allocator(1024 * 1024);
|
||||
|
||||
// 第一帧
|
||||
void* frame1_ptr = allocator.Allocate(256);
|
||||
void* frame1_ptr2 = allocator.Allocate(128);
|
||||
// ... 第一帧渲染逻辑
|
||||
|
||||
// 帧结束时清空
|
||||
allocator.Clear();
|
||||
|
||||
// 第二帧重新开始
|
||||
void* frame2_ptr = allocator.Allocate(256);
|
||||
// 此时 frame1_ptr 已无效,但内存已被回收复用
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [LinearAllocator 总览](linear-allocator.md) - 返回类总览
|
||||
35
docs/api/memory/linear-allocator/free.md
Normal file
35
docs/api/memory/linear-allocator/free.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# LinearAllocator::Free
|
||||
|
||||
```cpp
|
||||
void Free(void* ptr) override;
|
||||
```
|
||||
|
||||
此方法对 LinearAllocator 无实际效果。线性分配器不支持单个内存块的释放,因为内存是顺序分配的,释放中间某块会破坏后续分配的完整性。需要释放所有内存时使用 `Clear()` 方法。
|
||||
|
||||
**参数:**
|
||||
- `ptr` - 被忽略
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(1)(空操作)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Memory/LinearAllocator.h>
|
||||
|
||||
LinearAllocator allocator(1024);
|
||||
void* ptr = allocator.Allocate(256);
|
||||
void* ptr2 = allocator.Allocate(128);
|
||||
|
||||
// Free 实际上什么都不做
|
||||
allocator.Free(ptr);
|
||||
allocator.Free(ptr2);
|
||||
|
||||
// 如需释放所有内存,应使用 Clear
|
||||
allocator.Clear();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [LinearAllocator 总览](linear-allocator.md) - 返回类总览
|
||||
33
docs/api/memory/linear-allocator/get-capacity.md
Normal file
33
docs/api/memory/linear-allocator/get-capacity.md
Normal file
@@ -0,0 +1,33 @@
|
||||
# LinearAllocator::GetCapacity
|
||||
|
||||
```cpp
|
||||
size_t GetCapacity() const;
|
||||
```
|
||||
|
||||
返回分配器的总容量,即预分配缓冲区的大小。此值在构造时确定,之后保持不变。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** 总容量(字节数)
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Memory/LinearAllocator.h>
|
||||
|
||||
LinearAllocator allocator(1024 * 1024); // 1MB
|
||||
|
||||
size_t capacity = allocator.GetCapacity(); // 1048576
|
||||
|
||||
allocator.Allocate(512);
|
||||
allocator.Allocate(256);
|
||||
|
||||
size_t used = allocator.GetUsedSize(); // 768
|
||||
size_t remaining = allocator.GetCapacity() - allocator.GetUsedSize(); // 1047808
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [LinearAllocator 总览](linear-allocator.md) - 返回类总览
|
||||
41
docs/api/memory/linear-allocator/get-marker.md
Normal file
41
docs/api/memory/linear-allocator/get-marker.md
Normal file
@@ -0,0 +1,41 @@
|
||||
# LinearAllocator::GetMarker
|
||||
|
||||
```cpp
|
||||
void* GetMarker() const;
|
||||
```
|
||||
|
||||
获取当前分配位置的标记。标记是一个指向当前偏移量的指针,可用于 `SetMarker` 恢复到该位置。此方法用于实现临时分配的撤销功能。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** 当前分配位置的指针标记
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Memory/LinearAllocator.h>
|
||||
|
||||
LinearAllocator allocator(1024);
|
||||
|
||||
// 分配一些数据
|
||||
void* ptr1 = allocator.Allocate(128);
|
||||
|
||||
// 保存标记(用于回滚点)
|
||||
void* marker = allocator.GetMarker();
|
||||
|
||||
// 分配临时数据
|
||||
void* temp = allocator.Allocate(64);
|
||||
void* temp2 = allocator.Allocate(32);
|
||||
|
||||
// 临时数据用完了,恢复到标记位置
|
||||
allocator.SetMarker(marker);
|
||||
|
||||
// 此时 temp 和 temp2 的内存已被回收
|
||||
// ptr1 仍然有效
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [LinearAllocator 总览](linear-allocator.md) - 返回类总览
|
||||
39
docs/api/memory/linear-allocator/get-used-size.md
Normal file
39
docs/api/memory/linear-allocator/get-used-size.md
Normal file
@@ -0,0 +1,39 @@
|
||||
# LinearAllocator::GetUsedSize
|
||||
|
||||
```cpp
|
||||
size_t GetUsedSize() const;
|
||||
```
|
||||
|
||||
返回当前已使用的字节数,即内部偏移量的值。此值在 `Allocate` 后增加,在 `Clear` 或 `SetMarker` 后可能减少(取决于设置的目标位置)。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** 已使用的字节数
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Memory/LinearAllocator.h>
|
||||
|
||||
LinearAllocator allocator(1024);
|
||||
|
||||
size_t before = allocator.GetUsedSize(); // 0
|
||||
|
||||
allocator.Allocate(128);
|
||||
allocator.Allocate(256);
|
||||
|
||||
size_t after = allocator.GetUsedSize(); // 384
|
||||
|
||||
void* marker = allocator.GetMarker();
|
||||
allocator.Allocate(64);
|
||||
size_t with_temp = allocator.GetUsedSize(); // 448
|
||||
|
||||
allocator.SetMarker(marker);
|
||||
size_t after_rollback = allocator.GetUsedSize(); // 384
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [LinearAllocator 总览](linear-allocator.md) - 返回类总览
|
||||
35
docs/api/memory/linear-allocator/linear-allocator.md
Normal file
35
docs/api/memory/linear-allocator/linear-allocator.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# LinearAllocator::LinearAllocator
|
||||
|
||||
```cpp
|
||||
explicit LinearAllocator(size_t size, IAllocator* parent = nullptr);
|
||||
```
|
||||
|
||||
构造一个线性分配器,预分配指定大小的缓冲区。如果提供了 `parent` 分配器,则使用它分配底层缓冲区;否则使用系统默认分配(`_aligned_malloc`,8 字节对齐)。
|
||||
|
||||
**参数:**
|
||||
- `size` - 预分配的缓冲区大小(字节数)
|
||||
- `parent` - 父分配器,用于分配底层缓冲区,默认为 `nullptr`(使用系统分配)
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(n),需要分配 `size` 大小的缓冲区
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Memory/LinearAllocator.h>
|
||||
|
||||
// 使用系统分配器创建 1MB 线性分配器
|
||||
LinearAllocator allocator1(1024 * 1024);
|
||||
|
||||
// 使用指定的父分配器
|
||||
IAllocator* parent = MemoryManager::Get().GetSystemAllocator();
|
||||
LinearAllocator allocator2(1024 * 1024, parent);
|
||||
|
||||
// 默认 8 字节对齐
|
||||
void* ptr = allocator1.Allocate(256);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [LinearAllocator 总览](linear-allocator.md) - 返回类总览
|
||||
34
docs/api/memory/linear-allocator/reallocate.md
Normal file
34
docs/api/memory/linear-allocator/reallocate.md
Normal file
@@ -0,0 +1,34 @@
|
||||
# LinearAllocator::Reallocate
|
||||
|
||||
```cpp
|
||||
void* Reallocate(void* ptr, size_t newSize) override;
|
||||
```
|
||||
|
||||
在缓冲区当前位置分配新内存。此方法始终在缓冲区末尾分配新内存,而不是尝试调整现有块的大小。返回的指针可能与输入的 `ptr` 不同。如果剩余空间不足,返回 `nullptr` 且原指针保持不变。
|
||||
|
||||
**参数:**
|
||||
- `ptr` - 被忽略(始终分配新内存)
|
||||
- `newSize` - 新请求的字节数
|
||||
|
||||
**返回:** 分配成功返回新内存指针,失败返回 `nullptr`
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Memory/LinearAllocator.h>
|
||||
|
||||
LinearAllocator allocator(1024);
|
||||
void* ptr1 = allocator.Allocate(128);
|
||||
|
||||
// Reallocate 忽略原 ptr,在当前位置分配新内存
|
||||
void* ptr2 = allocator.Reallocate(ptr1, 256);
|
||||
|
||||
// ptr1 和 ptr2 可能相同也可能不同
|
||||
// 都不会被释放,新内存始终在缓冲区末尾分配
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [LinearAllocator 总览](linear-allocator.md) - 返回类总览
|
||||
41
docs/api/memory/linear-allocator/set-marker.md
Normal file
41
docs/api/memory/linear-allocator/set-marker.md
Normal file
@@ -0,0 +1,41 @@
|
||||
# LinearAllocator::SetMarker
|
||||
|
||||
```cpp
|
||||
void SetMarker(void* marker);
|
||||
```
|
||||
|
||||
恢复到之前通过 `GetMarker` 获取的标记位置。所有在标记之后的分配都将被丢弃,内部偏移量重置为该标记位置。此方法不会释放内存,只是移动偏移量指针。
|
||||
|
||||
**参数:**
|
||||
- `marker` - 通过 `GetMarker` 获取的标记指针
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Memory/LinearAllocator.h>
|
||||
|
||||
LinearAllocator allocator(1024);
|
||||
|
||||
// 基础数据
|
||||
void* base = allocator.Allocate(256);
|
||||
void* marker = allocator.GetMarker();
|
||||
|
||||
// 可选的扩展数据
|
||||
void* ext1 = allocator.Allocate(64);
|
||||
void* ext2 = allocator.Allocate(128);
|
||||
|
||||
// 决定不使用扩展数据,回滚
|
||||
allocator.SetMarker(marker);
|
||||
|
||||
// 扩展数据内存已被回收
|
||||
// 可以重新分配其他数据
|
||||
void* new_data = allocator.Allocate(128);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [LinearAllocator 总览](linear-allocator.md) - 返回类总览
|
||||
29
docs/api/memory/linear-allocator/~linear-allocator.md
Normal file
29
docs/api/memory/linear-allocator/~linear-allocator.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# LinearAllocator::~LinearAllocator
|
||||
|
||||
```cpp
|
||||
~LinearAllocator() override;
|
||||
```
|
||||
|
||||
销毁线性分配器,释放预分配的缓冲区。如果提供了 `parent` 分配器,则使用它释放缓冲区;否则使用系统默认释放(`::operator delete`)。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Memory/LinearAllocator.h>
|
||||
|
||||
{
|
||||
LinearAllocator allocator(1024 * 1024);
|
||||
void* ptr = allocator.Allocate(256);
|
||||
// ... 使用 allocator
|
||||
} // 析构时自动释放 1MB 缓冲区
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [LinearAllocator 总览](linear-allocator.md) - 返回类总览
|
||||
Reference in New Issue
Block a user