修复问题: - containers: HashMap include 路径修复 - core: RefCounted 析构函数访问级别, Event::begin/end 返回值说明 - memory: LinearAllocator::GetMarker 返回偏移量非指针 - resources: LoadAsync 示例使用不存在的模板方法 - rhi: OpenGL 链接错误, ShaderType 枚举缺失8个类型, 链接修复 - threading: SpinLock STL 兼容方法说明, Mutex const 方法说明
1.0 KiB
1.0 KiB
LinearAllocator::GetMarker
void* GetMarker() const;
获取当前分配位置的标记。标记是内部偏移量(m_offset)的快照,可用于 SetMarker 恢复到该位置。此方法用于实现临时分配的撤销功能。
参数: 无
返回: 当前位置标记(偏移量值),类型为 void*
注意: 返回值是偏移量数值,不是指针。将其传给 SetMarker 可恢复到此分配位置。
复杂度: O(1)
示例:
#include <XCEngine/Memory/LinearAllocator.h>
LinearAllocator allocator(1024);
// 分配一些数据
void* ptr1 = allocator.Allocate(128);
// 保存标记(用于回滚点)
void* marker = allocator.GetMarker();
// 分配临时数据
void* temp = allocator.Allocate(64);
void* temp2 = allocator.Allocate(32);
// 临时数据用完了,恢复到标记位置
allocator.SetMarker(marker);
// 此时 temp 和 temp2 的内存已被回收
// ptr1 仍然有效
相关文档
- LinearAllocator 总览 - 返回类总览