ScopedMemoryAllocation is a helper function for allocating memory blocks from the backend while adding the security and ease of use of the RAII idiom.
More...
#include <ScopedMemoryAllocation.h>
ScopedMemoryAllocation is a helper function for allocating memory blocks from the backend while adding the security and ease of use of the RAII idiom.
Usage notes: This is meant to be used only temporarily within a particular block of code. The class doesn't take a reference to the network backend. Check handle() for nullptr, which is the failure of allocation. Memory is freed automatically once out of scope.
◆ ScopedMemoryAllocation() [1/2]
nvneural::ScopedMemoryAllocation::ScopedMemoryAllocation |
( |
INetworkBackend * |
pBackend, |
|
|
size_t |
bufferSize |
|
) |
| |
|
inline |
Creates a temporary memory allocation using a network backend.
The memory allocated is in the backend's address space (cuDevicePtr for CUDA).
- Parameters
-
pBackend | Backend performing the allocation |
bufferSize | Size of buffer to request, in bytes |
◆ ScopedMemoryAllocation() [2/2]
nvneural::ScopedMemoryAllocation::ScopedMemoryAllocation |
( |
INetworkBackend * |
pBackend, |
|
|
size_t |
bufferSize, |
|
|
const char * |
pTrackingKey |
|
) |
| |
|
inline |
Creates a temporary memory allocation, using a network backend, of the requested size and allows tracking of the memory block using a user-defined key.
It is best practice to use the layer's name at this key. The memory allocated is in the backend's address space (cuDevicePtr for CUDA).
- Parameters
-
pBackend | Backend performing the allocation |
bufferSize | Size of buffer to request, in bytes |
pTrackingKey | A string key, usually the layer's name, which allows tracking of this allocation's information, nullptr to disable |
◆ asPointer()
void* nvneural::ScopedMemoryAllocation::asPointer |
( |
| ) |
|
|
inline |
Returns the pointer to the allocated memory block.
- Returns
- A void pointer to the memory block.
◆ handle()
MemoryHandle nvneural::ScopedMemoryAllocation::handle |
( |
| ) |
const |
|
inline |
Returns the memory handle of the allocated memory block.
- Returns
- The memory handle, nullptr indicates a failed allocation.
◆ operator=()
Takes ownership of an allocation from another ScopedMemoryAllocation.
- Parameters
-
moveFrom | rvalue reference to the source allocation object |
The documentation for this class was generated from the following file: