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 个断裂引用
2026-03-19 00:22:30 +08:00
|
|
|
# Array::SetAllocator()
|
|
|
|
|
|
|
|
|
|
```cpp
|
|
|
|
|
void SetAllocator(Memory::IAllocator* allocator);
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
设置数组使用的内存分配器。
|
|
|
|
|
|
|
|
|
|
**用途:** 允许自定义内存分配策略,如使用对象池、固定大小分配器或调试分配器。
|
|
|
|
|
|
|
|
|
|
**参数:**
|
|
|
|
|
- `allocator` - 指向 `Memory::IAllocator` 接口的指针。如果为 `nullptr`,使用默认 `::operator new/delete`。
|
|
|
|
|
|
|
|
|
|
**注意:**
|
|
|
|
|
- 如果数组已有元素,设置新的分配器后,**不会**迁移现有元素
|
|
|
|
|
- 仅影响后续的内存分配操作
|
|
|
|
|
- 通常在构造后立即调用,或在数组为空时调用
|
|
|
|
|
|
|
|
|
|
**线程安全:** ❌ 操作期间不可并发访问
|
|
|
|
|
|
|
|
|
|
**示例:**
|
|
|
|
|
|
|
|
|
|
```cpp
|
|
|
|
|
// 使用线性分配器(适合帧分配)
|
|
|
|
|
auto* linear = new Memory::LinearAllocator(1024 * 1024);
|
|
|
|
|
|
|
|
|
|
Containers::Array<int> arr;
|
|
|
|
|
arr.SetAllocator(linear);
|
|
|
|
|
|
2026-03-19 01:14:20 +08:00
|
|
|
// 使用对象池分配器
|
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 个断裂引用
2026-03-19 00:22:30 +08:00
|
|
|
auto* pool = new Memory::PoolAllocator(sizeof(MyObject), 100);
|
|
|
|
|
Containers::Array<MyObject> objects;
|
|
|
|
|
objects.SetAllocator(pool);
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 相关文档
|
|
|
|
|
|
|
|
|
|
- [Array 总览](array.md) - 返回类总览
|