A borrow of scratch memory from a Queue's workspace arena, returned to the arena when the handle goes out of scope.
auto ws = ctx.workspace(foo_buffer_size<B>(ctx, A));
foo<B>(ctx, A, ws.span());
Releasing a lease frees nothing (the memory belongs to the Queue), so the pointer stays valid for kernels still in flight; the bytes are handed to the next lease instead. On an in-order Queue that is safe by construction. On an out-of-order Queue, release() drains the queue first (see release()).
Leases nest, and the arena never moves leased memory. Release in reverse order of acquisition (scope-bound handles do this for free); an out-of-order release is safe but keeps its bytes reserved until every later lease is released, and debug builds assert on it.
- Warning
- Reassigning a live lease (ws = ctx.workspace(bigger);) acquires the new loan before the old one is returned, so a loop that reassigns every iteration ratchets the arena upward. Call ws.release() first.
- Note
- Tied to one Queue and not thread-safe, like Queue itself.
- See also
- Workspace
Definition at line 46 of file workspace.hh.