Files
XCSDD/docs/api/memory/linear-allocator/clear.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

38 lines
886 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# LinearAllocator::Clear
```cpp
void Clear();
```
清空分配器,将内部偏移量重置为 0所有已分配的内存被视为已释放。下一次 `Allocate` 将从缓冲区起始位置开始。此方法不实际释放或修改底层内存,适合作为帧分配器使用,每帧开始时调用 Clear 重置。
**参数:**
**返回:**
**复杂度:** O(1)
**示例:**
```cpp
#include <XCEngine/Memory/LinearAllocator.h>
LinearAllocator allocator(1024 * 1024);
// 第一帧
void* frame1_ptr = allocator.Allocate(256);
void* frame1_ptr2 = allocator.Allocate(128);
// ... 第一帧渲染逻辑
// 帧结束时清空
allocator.Clear();
// 第二帧重新开始
void* frame2_ptr = allocator.Allocate(256);
// 此时 frame1_ptr 已无效,但内存已被回收复用
```
## 相关文档
- [LinearAllocator 总览](linear-allocator.md) - 返回类总览