legate::ScopedAllocator#
-
class ScopedAllocator#
A simple allocator backed by Buffer objects.
For each allocation request, this allocator creates a 1D Buffer of
std::int8_tand returns the raw pointer to it. By default, all allocations are deallocated when the allocator is destroyed, and can optionally be made alive until the task finishes by making the allocator unscoped.Public Functions
- explicit ScopedAllocator(
- Memory::Kind kind,
- bool scoped = true,
- std::size_t alignment = DEFAULT_ALIGNMENT
Create a
ScopedAllocatorfor a specific memory kind.- Parameters:
kind –
Memory::Kindof the memory on which the Buffer should be createdscoped – If true, the allocator is scoped; i.e., lifetimes of allocations are tied to the allocator’s lifetime. Otherwise, the allocations are alive until the task finishes (and unless explicitly deallocated).
alignment – Alignment for the allocations
- Throws:
std::domain_error – If
alignmentis 0, or not a power of 2.
-
void *allocate(std::size_t bytes)#
Allocates a contiguous buffer of the given
Memory::KindWhen the allocator runs out of memory, the runtime will fail with an error message. Otherwise, the function returns a valid pointer. If
bytesis0, returnsnullptr.See also
- Parameters:
bytes – Size of the allocation in bytes
- Returns:
A raw pointer to the allocation
-
void deallocate(void *ptr)#
Deallocates an allocation.
The input pointer must be one that was previously returned by an
allocate()call. Ifptrisnullptr, this call does nothing.See also
- Parameters:
ptr – Pointer to the allocation to deallocate
- Throws:
std::invalid_argument – If
ptrwas not allocated by this allocator.
-
class Impl#