ScopedMemoryAllocation¶
class ScopedMemoryAllocation
Allocates a block of memory with the given size in the given pool.
That allocation will be restricted to the current scope, and will be freed automatically when the scope ends.
Functions¶
| Name | Description |
|---|---|
| ScopedMemoryAllocation | Default constructor. |
| ScopedMemoryAllocation | Creates a new scoped memory allocation. |
| ScopedMemoryAllocation | Creates a new scoped aligned memory allocation. |
| ~ScopedMemoryAllocation | Releases the allocated memory. |
| PointerOf | Gets the allocated memory address. |
| As | Converts the allocated memory address to a different type. |
| Address | Gets the allocated memory address. |
Function Details¶
Address¶
[[nodiscard]] inline AmVoidPtr Address() const
Gets the allocated memory address.
- Return
- The allocated memory address.
As¶
template<typename T, typename std::enable_if_t<std::is_pointer_v<T>, bool> = false> [[nodiscard]] inline T As() const
Converts the allocated memory address to a different type.
- Return
- The allocated memory address converted to the specified type.
PointerOf¶
template<typename T> [[nodiscard]] inline T* PointerOf() const
Gets the allocated memory address.
- Return
- The allocated memory address.
ScopedMemoryAllocation¶
ScopedMemoryAllocation() = default
Default constructor.
ScopedMemoryAllocation(eMemoryPoolKind pool, AmSize size, const char* file, AmUInt32 line)
Creates a new scoped memory allocation.
- Parameter
pool - The memory pool to allocate from.
- Parameter
size - The size of the block to allocate.
- Parameter
file - The file in which the allocation was made.
- Parameter
line - The line in which the allocation was made.
ScopedMemoryAllocation(eMemoryPoolKind pool, AmSize size, AmUInt32 alignment, const char* file, AmUInt32 line)
Creates a new scoped aligned memory allocation.
- Parameter
pool - The memory pool to allocate from.
- Parameter
size - The size of the block to allocate.
- Parameter
alignment - The alignment of the block to allocate.
- Parameter
file - The file in which the allocation was made.
- Parameter
line - The line in which the allocation was made.
~ScopedMemoryAllocation¶
~ScopedMemoryAllocation()
Releases the allocated memory.