Files
XCSDD/docs/api/containers/array/setallocator.md
ssdfasd 58a83f445a fix: improve doc link navigation and tree display
- Fix link resolution with proper relative/absolute path handling
- Improve link styling with underline decoration
- Hide leaf nodes from tree, only show directories
- Fix log file path for packaged app
2026-03-19 12:44:08 +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);

相关文档