Files
XCEngine/docs/api/memory/linear-allocator/get-used-size.md

40 lines
866 B
Markdown
Raw Normal View History

# LinearAllocator::GetUsedSize
```cpp
size_t GetUsedSize() const;
```
返回当前已使用的字节数,即内部偏移量的值。此值在 `Allocate` 后增加,在 `Clear``SetMarker` 后可能减少(取决于设置的目标位置)。
**参数:** 无
**返回:** 已使用的字节数
**复杂度:** O(1)
**示例:**
```cpp
#include <XCEngine/Memory/LinearAllocator.h>
LinearAllocator allocator(1024);
size_t before = allocator.GetUsedSize(); // 0
allocator.Allocate(128);
allocator.Allocate(256);
size_t after = allocator.GetUsedSize(); // 384
void* marker = allocator.GetMarker();
allocator.Allocate(64);
size_t with_temp = allocator.GetUsedSize(); // 448
allocator.SetMarker(marker);
size_t after_rollback = allocator.GetUsedSize(); // 384
```
## 相关文档
- [LinearAllocator 总览](linear-allocator.md) - 返回类总览