fix: improve doc link navigation and tree display
- Fix link resolution with proper relative/absolute path handling - Improve link styling with underline decoration - Hide leaf nodes from tree, only show directories - Fix log file path for packaged app
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) - 返回类总览
|
||||
43
docs/api/memory/linear-allocator/get-marker.md
Normal file
43
docs/api/memory/linear-allocator/get-marker.md
Normal file
@@ -0,0 +1,43 @@
|
||||
# LinearAllocator::GetMarker
|
||||
|
||||
```cpp
|
||||
void* GetMarker() const;
|
||||
```
|
||||
|
||||
获取当前分配位置的标记。标记是内部偏移量(`m_offset`)的快照,可用于 `SetMarker` 恢复到该位置。此方法用于实现临时分配的撤销功能。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** 当前位置标记(偏移量值),类型为 `void*`
|
||||
|
||||
**注意:** 返回值是偏移量数值,不是指针。将其传给 `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) - 返回类总览
|
||||
66
docs/api/memory/linear-allocator/linear-allocator.md
Normal file
66
docs/api/memory/linear-allocator/linear-allocator.md
Normal file
@@ -0,0 +1,66 @@
|
||||
# LinearAllocator
|
||||
|
||||
**命名空间**: `XCEngine::Memory`
|
||||
|
||||
**类型**: `class`
|
||||
|
||||
**描述**: 线性分配器,适合帧分配和临时对象。
|
||||
|
||||
## 概述
|
||||
|
||||
`LinearAllocator` 是一种顺序分配器,预分配一个大缓冲区,每次分配从缓冲区起始位置顺序分配,偏移量递增。它不适合需要释放任意块的场景,但分配和清除非常高效,常用于帧分配器。
|
||||
|
||||
## 公共方法
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `LinearAllocator` | 构造线性分配器 |
|
||||
| `~LinearAllocator` | 析构函数,释放底层缓冲区 |
|
||||
| `Allocate` | 顺序分配内存 |
|
||||
| `Free` | 无效果(不支持) |
|
||||
| `Reallocate` | 不支持(始终返回 nullptr) |
|
||||
| `Clear` | 清空所有分配 |
|
||||
| `GetMarker` | 获取当前位置标记 |
|
||||
| `SetMarker` | 回滚到指定标记位置 |
|
||||
| `GetUsedSize` | 获取已使用字节数 |
|
||||
| `GetCapacity` | 获取总容量 |
|
||||
|
||||
## 构造函数
|
||||
|
||||
```cpp
|
||||
explicit LinearAllocator(size_t size, IAllocator* parent = nullptr);
|
||||
~LinearAllocator() override;
|
||||
```
|
||||
|
||||
构造一个线性分配器,预分配指定大小的缓冲区。如果提供了 `parent` 分配器,则使用它分配底层缓冲区;否则使用系统默认分配(`_aligned_malloc`,8 字节对齐)。
|
||||
|
||||
**参数:**
|
||||
- `size` - 预分配的缓冲区大小(字节数)
|
||||
- `parent` - 父分配器,用于分配底层缓冲区,默认为 `nullptr`(使用系统分配)
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**复杂度:** O(n),需要分配 `size` 大小的缓冲区
|
||||
|
||||
**注意:** `Free` 和 `Reallocate` 方法无实际效果。`Free` 是空操作,`Reallocate` 始终返回 `nullptr`。
|
||||
|
||||
**示例:**
|
||||
|
||||
```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);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Memory 模块总览](../memory.md) - 返回模块总览
|
||||
- [IAllocator](../allocator/allocator.md) - 分配器接口
|
||||
35
docs/api/memory/linear-allocator/reallocate.md
Normal file
35
docs/api/memory/linear-allocator/reallocate.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# LinearAllocator::Reallocate
|
||||
|
||||
```cpp
|
||||
void* Reallocate(void* ptr, size_t newSize) override;
|
||||
```
|
||||
|
||||
线性分配器不支持重新分配。此方法始终返回 `nullptr`,原内存块保持不变。由于线性分配器的顺序分配特性,无法调整现有块的大小。
|
||||
|
||||
**参数:**
|
||||
- `ptr` - 不被使用(始终返回 nullptr)
|
||||
- `newSize` - 不被使用(始终返回 nullptr)
|
||||
|
||||
**返回:** 始终返回 `nullptr`
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Memory/LinearAllocator.h>
|
||||
|
||||
LinearAllocator allocator(1024);
|
||||
void* ptr1 = allocator.Allocate(128);
|
||||
|
||||
// Reallocate 不支持,始终返回 nullptr
|
||||
void* ptr2 = allocator.Reallocate(ptr1, 256);
|
||||
if (!ptr2) {
|
||||
// 线性分配器不支持重新分配
|
||||
// ptr1 仍然有效
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [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