docs: update memory and threading API docs

This commit is contained in:
2026-03-20 02:35:24 +08:00
parent c5b17239ca
commit fd792b7df1
103 changed files with 2485 additions and 673 deletions

View File

@@ -4,6 +4,8 @@
**类型**: `class` (abstract interface)
**头文件**: `XCEngine/Memory/Allocator.h`
**描述**: 内存分配器抽象接口,定义标准分配协议。
## 概述
@@ -16,24 +18,24 @@
| 方法 | 描述 |
|------|------|
| `Allocate` | 分配内存 |
| `Free` | 释放内存 |
| `Reallocate` | 重新分配内存 |
| [`Allocate`](allocate.md) | 分配内存 |
| [`Free`](free.md) | 释放内存 |
| [`Reallocate`](reallocate.md) | 重新分配内存 |
### 统计信息
| 方法 | 描述 |
|------|------|
| `GetTotalAllocated` | 获取已分配总字节数 |
| `GetTotalFreed` | 获取已释放总字节数 |
| `GetPeakAllocated` | 获取峰值分配字节数 |
| `GetAllocationCount` | 获取分配次数 |
| [`GetTotalAllocated`](get-total-allocated.md) | 获取已分配总字节数 |
| [`GetTotalFreed`](get-total-freed.md) | 获取已释放总字节数 |
| [`GetPeakAllocated`](get-peak-allocated.md) | 获取峰值分配字节数 |
| [`GetAllocationCount`](get-allocation-count.md) | 获取分配次数 |
### 元信息
| 方法 | 描述 |
|------|------|
| `GetName` | 获取分配器名称 |
| [`GetName`](get-name.md) | 获取分配器名称 |
## 使用示例
@@ -70,3 +72,4 @@ public:
- [MemoryManager](../manager/manager.md) - 内存管理器
- [LinearAllocator](../linear-allocator/linear-allocator.md) - 线性分配器
- [PoolAllocator](../pool-allocator/pool-allocator.md) - 内存池分配器
- [ProxyAllocator](../proxy-allocator/proxy-allocator.md) - 代理分配器

View File

@@ -30,9 +30,9 @@ public:
void Free(void* ptr) override {
if (ptr) {
size_t size = 256; // 需要外部记录
// size 需要分配器内部记录或通过其他机制获取
::operator delete(ptr);
m_current -= size;
m_current -= 256; // 示例中硬编码
}
}

View File

@@ -18,22 +18,20 @@ virtual size_t GetTotalFreed() const = 0;
#include <XCEngine/Memory/Allocator.h>
class MyAllocator : public IAllocator {
size_t m_freed = 0;
public:
void* Allocate(size_t size, size_t alignment = 0) override { return ::operator new(size); }
void Free(void* ptr) override {
if (ptr) {
size_t size = 256; // 需要外部记录
// size 需要分配器内部记录或通过其他机制获取
::operator delete(ptr);
m_freed += size;
}
}
void* Reallocate(void* ptr, size_t newSize) override { /* ... */ }
size_t GetTotalAllocated() const override { return 0; }
size_t GetTotalFreed() const override { return m_freed; }
size_t GetTotalFreed() const override { return 0; } // 示例未实际统计
size_t GetPeakAllocated() const override { return 0; }
size_t GetAllocationCount() const override { return 0; }
const char* GetName() const override { return "MyAllocator"; }
@@ -42,7 +40,7 @@ public:
MyAllocator alloc;
void* ptr = alloc.Allocate(128);
alloc.Free(ptr);
size_t freed = alloc.GetTotalFreed(); // 返回 128
size_t freed = alloc.GetTotalFreed(); // 返回 0示例未统计
```
## 相关文档