docs: update containers API docs
This commit is contained in:
@@ -4,33 +4,24 @@
|
||||
void SetAllocator(Memory::IAllocator* allocator);
|
||||
```
|
||||
|
||||
设置数组使用的内存分配器。
|
||||
|
||||
**用途:** 允许自定义内存分配策略,如使用对象池、固定大小分配器或调试分配器。
|
||||
设置数组的内存分配器指针(当前实现未使用此分配器)。
|
||||
|
||||
**参数:**
|
||||
- `allocator` - 指向 `Memory::IAllocator` 接口的指针。如果为 `nullptr`,使用默认 `::operator new/delete`。
|
||||
- `allocator` - 指向 `Memory::IAllocator` 接口的指针
|
||||
|
||||
**注意:**
|
||||
- 此方法仅存储分配器指针,**当前实现未使用该分配器进行内存分配**
|
||||
- 所有内存分配仍使用 `::operator new/delete`
|
||||
- 如果数组已有元素,设置新的分配器后,**不会**迁移现有元素
|
||||
- 仅影响后续的内存分配操作
|
||||
- 通常在构造后立即调用,或在数组为空时调用
|
||||
- 仅影响后续的内存分配操作(但实际上分配器未被使用)
|
||||
|
||||
**线程安全:** ❌ 操作期间不可并发访问
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
// 使用线性分配器(适合帧分配)
|
||||
auto* linear = new Memory::LinearAllocator(1024 * 1024);
|
||||
|
||||
Containers::Array<int> arr;
|
||||
arr.SetAllocator(linear);
|
||||
|
||||
// 使用对象池分配器
|
||||
auto* pool = new Memory::PoolAllocator(sizeof(MyObject), 100);
|
||||
Containers::Array<MyObject> objects;
|
||||
objects.SetAllocator(pool);
|
||||
XCEngine::Containers::Array<int> arr;
|
||||
arr.SetAllocator(customAllocator);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
Reference in New Issue
Block a user