docs: update memory and threading API docs
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
|
||||
**类型**: `class`
|
||||
|
||||
**头文件**: `XCEngine/Memory/LinearAllocator.h`
|
||||
|
||||
**描述**: 线性分配器,适合帧分配和临时对象。
|
||||
|
||||
## 概述
|
||||
@@ -14,51 +16,21 @@
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `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);
|
||||
```
|
||||
| [`LinearAllocator`](constructor.md) | 构造线性分配器 |
|
||||
| [`~LinearAllocator`](~linear-allocator.md) | 析构函数,释放底层缓冲区 |
|
||||
| [`Allocate`](allocate.md) | 顺序分配内存 |
|
||||
| [`Free`](free.md) | 无效果(不支持) |
|
||||
| [`Reallocate`](reallocate.md) | 不支持(始终返回 nullptr) |
|
||||
| [`Clear`](clear.md) | 清空所有分配 |
|
||||
| [`GetMarker`](get-marker.md) | 获取当前位置标记 |
|
||||
| [`SetMarker`](set-marker.md) | 回滚到指定标记位置 |
|
||||
| [`GetUsedSize`](get-used-size.md) | 获取已使用字节数 |
|
||||
| [`GetCapacity`](get-capacity.md) | 获取总容量 |
|
||||
| [`GetName`](get-name.md) | 获取分配器名称 |
|
||||
| [`GetTotalAllocated`](get-total-allocated.md) | 获取累计分配字节数 |
|
||||
| [`GetTotalFreed`](get-total-freed.md) | 获取累计释放字节数 |
|
||||
| [`GetPeakAllocated`](get-peak-allocated.md) | 获取峰值分配字节数 |
|
||||
| [`GetAllocationCount`](get-allocation-count.md) | 获取分配次数 |
|
||||
|
||||
## 相关文档
|
||||
|
||||
|
||||
Reference in New Issue
Block a user