Files
XCEngine/docs/api/memory/proxy-allocator/reallocate.md
ssdfasd 98c764bab9 docs: Fix memory module documentation discrepancies
- Add missing PoolAllocator class overview with methods table
- Add missing LinearAllocator class overview with methods table
- Add missing ProxyAllocator class overview with methods table
- Fix PoolAllocator::Allocate example code and comments
- Clarify ProxyAllocator::Free totalFreed calculation behavior
- Fix CreateLinearAllocator complexity from O(size) to O(1)
- Add note about Reallocate thread safety in ProxyAllocator
2026-03-19 00:48:44 +08:00

39 lines
973 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.
# ProxyAllocator::Reallocate
```cpp
void* Reallocate(void* ptr, size_t newSize) override;
```
重新分配内存。调用转发到底层分配器,不记录额外统计信息(底层分配器的返回值直接返回)。此方法线程安全,内部使用互斥锁保护。
**参数:**
- `ptr` - 现有内存块指针
- `newSize` - 新的字节大小
**返回:** 成功返回新指针,失败返回 `nullptr`(由底层分配器决定)
**复杂度:** O(n)(底层分配器 + 数据复制)
**示例:**
```cpp
#include <XCEngine/Memory/MemoryManager.h>
#include <XCEngine/Memory/ProxyAllocator.h>
IAllocator* sysAlloc = MemoryManager::Get().GetSystemAllocator();
ProxyAllocator proxy(sysAlloc, "TrackedAlloc");
void* p1 = proxy.Allocate(128);
void* p2 = proxy.Reallocate(p1, 256);
if (p2) {
// 重新分配成功
} else {
// 失败p1 仍然有效
}
```
## 相关文档
- [ProxyAllocator 总览](proxy-allocator.md) - 返回类总览