docs: update memory and threading API docs
This commit is contained in:
40
docs/api/memory/pool-allocator/get-allocation-count.md
Normal file
40
docs/api/memory/pool-allocator/get-allocation-count.md
Normal file
@@ -0,0 +1,40 @@
|
||||
# PoolAllocator::GetAllocationCount
|
||||
|
||||
```cpp
|
||||
size_t GetAllocationCount() const override;
|
||||
```
|
||||
|
||||
返回当前已分配块的数量。计算公式:`m_totalBlocks - m_freeBlocks`。
|
||||
|
||||
**参数:** 无
|
||||
|
||||
**返回:** 当前已分配块的数量
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Memory/PoolAllocator.h>
|
||||
|
||||
PoolAllocator pool(sizeof(int), 100);
|
||||
|
||||
size_t count = pool.GetAllocationCount(); // 0
|
||||
|
||||
void* blocks[10];
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
blocks[i] = pool.Allocate();
|
||||
}
|
||||
|
||||
count = pool.GetAllocationCount(); // 10
|
||||
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
pool.Free(blocks[i]);
|
||||
}
|
||||
|
||||
count = pool.GetAllocationCount(); // 5
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [PoolAllocator 总览](pool-allocator.md) - 返回类总览
|
||||
Reference in New Issue
Block a user