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
This commit is contained in:
38
docs/api/memory/pool-allocator/allocate.md
Normal file
38
docs/api/memory/pool-allocator/allocate.md
Normal file
@@ -0,0 +1,38 @@
|
||||
# PoolAllocator::Allocate
|
||||
|
||||
```cpp
|
||||
void* Allocate(size_t size, size_t alignment = 0) override;
|
||||
```
|
||||
|
||||
从内存池中分配一个空闲块。每次分配一个固定大小的块。如果 `size` 超过块大小或池中没有空闲块,返回 `nullptr`。分配操作从空闲链表头部取出一个块。
|
||||
|
||||
**参数:**
|
||||
- `size` - 请求的大小,如果超过构造时指定的块大小则分配失败
|
||||
- `alignment` - 被忽略(构造时确定)
|
||||
|
||||
**返回:** 分配成功返回块指针,池空返回 `nullptr`
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Memory/PoolAllocator.h>
|
||||
|
||||
// 创建能容纳 1000 个整数的内存池
|
||||
PoolAllocator pool(sizeof(int), 1000, alignof(int));
|
||||
|
||||
// 分配(忽略 size 参数,只分配固定大小的块)
|
||||
void* block1 = pool.Allocate(1); // 分配一块(实际大小为 sizeof(int))
|
||||
void* block2 = pool.Allocate(10000); // 也分配一块(实际大小为 sizeof(int))
|
||||
|
||||
if (block1 && block2) {
|
||||
// 使用分配的内存块
|
||||
int* arr = static_cast<int*>(block1);
|
||||
arr[0] = 42;
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [PoolAllocator 总览](pool-allocator.md) - 返回类总览
|
||||
Reference in New Issue
Block a user