Files
XCEngine/docs/api/containers/array/setallocator.md
ssdfasd 12ae6f561a docs: Fix containers module documentation discrepancies
- Array::SetAllocator: Remove reference to non-existent PoolAllocator class
- HashMap::SetAllocator: Remove reference to non-existent GetDefaultAllocator()
- HashMap::Copy/Move: Fix move constructor complexity (O(m_bucketCount), not O(1))
- HashMap::iterator: Remove C++20 structured bindings example
- String: Add missing links for operator+ and operator==/!=
2026-03-19 01:14:20 +08:00

1.0 KiB

Array::SetAllocator()

void SetAllocator(Memory::IAllocator* allocator);

设置数组使用的内存分配器。

用途: 允许自定义内存分配策略,如使用对象池、固定大小分配器或调试分配器。

参数:

  • allocator - 指向 Memory::IAllocator 接口的指针。如果为 nullptr,使用默认 ::operator new/delete

注意:

  • 如果数组已有元素,设置新的分配器后,不会迁移现有元素
  • 仅影响后续的内存分配操作
  • 通常在构造后立即调用,或在数组为空时调用

线程安全: 操作期间不可并发访问

示例:

// 使用线性分配器(适合帧分配)
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);

相关文档