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

41 lines
888 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.
# IAllocator::Free
```cpp
virtual void Free(void* ptr) = 0;
```
释放之前通过 `Allocate` 分配的内存块。如果 `ptr``nullptr`,则此调用无效果。部分分配器(如 LinearAllocator可能不支持此操作。
**参数:**
- `ptr` - 指向要释放内存块的指针
**返回:**
**复杂度:** O(1)(固定块释放)或 O(n)(需要搜索)
**示例:**
```cpp
#include <XCEngine/Memory/Allocator.h>
class MyAllocator : public IAllocator {
public:
void* Allocate(size_t size, size_t alignment = 0) override {
return ::operator new(size);
}
void Free(void* ptr) override {
if (ptr) ::operator delete(ptr);
}
// ... 其他方法实现
};
MyAllocator alloc;
void* ptr = alloc.Allocate(512);
alloc.Free(ptr); // 释放内存
```
## 相关文档
- [IAllocator 总览](allocator.md) - 返回类总览