Files
XCEngine/docs/api/memory/proxy-allocator/constructor.md
ssdfasd f5a34f8adc docs: 重构 API 文档 - components 和 scene 模块
- components: 修复英文标题为中文,添加缺失组件文档
  - 新增 camera-component, light-component, audio-source-component, audio-listener-component 类总览
  - 修复 get-position.md 格式
  - 更新 components.md 模块总览
- scene: 修复方法文档格式,新增缺失方法
  - 修复 find.md, create-game-object.md 英文标题
  - 新增 FindByID, SerializeToString, DeserializeFromString 方法文档
  - 更新 scene.md 类总览方法列表
2026-03-26 01:50:27 +08:00

1.0 KiB

ProxyAllocator::ProxyAllocator

ProxyAllocator(IAllocator* underlying, const char* name);

构造一个代理分配器,包装底层分配器并记录分配统计。所有 AllocateFreeReallocate 调用都会被转发到底层分配器,同时记录统计信息。名称用于日志和报告。

参数:

  • underlying - 被包装的底层分配器,不能为 nullptr
  • name - 代理分配器的名称字符串

返回:

复杂度: O(1)

线程安全: (内部使用 mutex 保护统计数据)

示例:

#include <XCEngine/Memory/MemoryManager.h>
#include <XCEngine/Memory/ProxyAllocator.h>

MemoryManager::Get().Initialize();

// 使用系统分配器作为底层
IAllocator* sysAlloc = MemoryManager::Get().GetSystemAllocator();
ProxyAllocator proxy(sysAlloc, "TempAllocations");

// 通过代理分配
void* ptr = proxy.Allocate(1024);
proxy.Free(ptr);

相关文档