docs: rebuild Memory API content
This commit is contained in:
@@ -1,31 +1,39 @@
|
||||
# MemoryManager::CreateLinearAllocator
|
||||
|
||||
创建新对象或资源。
|
||||
创建一个线性分配器。
|
||||
|
||||
```cpp
|
||||
std::unique_ptr<LinearAllocator> CreateLinearAllocator(size_t size);
|
||||
```
|
||||
|
||||
该方法声明于 `XCEngine/Memory/MemoryManager.h`,当前页面用于固定 `MemoryManager` 类目录下的方法级 canonical 路径。
|
||||
## 行为说明
|
||||
|
||||
**参数:**
|
||||
- `size` - 参数语义详见头文件声明。
|
||||
|
||||
**返回:** `std::unique_ptr<LinearAllocator>` - 返回值语义详见头文件声明。
|
||||
|
||||
**示例:**
|
||||
当前实现等价于:
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Memory/MemoryManager.h>
|
||||
|
||||
void Example() {
|
||||
XCEngine::Memory::MemoryManager object;
|
||||
// 根据上下文补齐参数后调用 MemoryManager::CreateLinearAllocator(...)。
|
||||
(void)object;
|
||||
}
|
||||
return std::make_unique<LinearAllocator>(size, m_systemAllocator);
|
||||
```
|
||||
|
||||
这意味着:
|
||||
|
||||
- 如果已经调用过 [Initialize](Initialize.md),新建的 `LinearAllocator` 会把系统分配器作为父分配器。
|
||||
- 如果还没初始化,`m_systemAllocator == nullptr`,`LinearAllocator` 会走自己的直接分配路径。
|
||||
|
||||
## 参数
|
||||
|
||||
- `size` - 线性缓冲区容量。
|
||||
|
||||
## 返回值
|
||||
|
||||
- `std::unique_ptr<LinearAllocator>` - 由调用方拥有的线性分配器。
|
||||
|
||||
## 生命周期注意事项
|
||||
|
||||
- 这个工厂不会把返回对象注册到 `MemoryManager` 内部,调用方仍然负责销毁它。
|
||||
- 如果它绑定了系统分配器作为父分配器,应在 [Shutdown](Shutdown.md) 之前销毁;否则析构时可能访问悬空的 `m_systemAllocator`。
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [返回类总览](MemoryManager.md)
|
||||
- [返回模块目录](../Memory.md)
|
||||
- [返回类型总览](MemoryManager.md)
|
||||
- [Initialize](Initialize.md)
|
||||
- [Shutdown](Shutdown.md)
|
||||
|
||||
Reference in New Issue
Block a user