spdl.pipeline.ArenaReservation¶
- class ArenaReservation(owner: _DirectPool, unit: int, limit: int)[source]¶
[Experimental] A public writable byte reservation obtained from a pool.
Users obtain this object from
spdl.pipeline.SharedMemorySegmentPool.reserve(); do not construct it with internal endpoint parameters. Its allocation and seal operations are the public caller interface, separate from transparent transport protocols:with pool.reserve() as unit: data = unit.allocate_bytes(128) data[:] = bytes(128) ticket = unit.seal()
Prefer one allocation for a collated payload. The caller computes offsets, creates tensor/array views and sends dtype, shape and other metadata beside the ticket through ordinary IPC.
seal()publishes only the byte extent from the segment start through the last allocation, including alignment padding.pool.recover(ticket)returns a context yielding that whole extent as one lifetime-owned memoryview; no payload decoding is implicit.Context exit aborts an unsealed reservation, but escaped producer storage continues to gate reuse. Seal creates an independent in-transit hold before returning the immutable ticket; losing it does not abort the allocation. After sealing, do not mutate producer aliases. Allocation sizes must be positive; sealing without allocations yields an empty recovered view and still requires exactly one recovery or discard.
- Parameters:
owner – Internal control endpoint; users obtain reservations from a pool.
unit – Allocation generation assigned by the pool.
limit – Positive allocation byte limit within one segment.
Added in version 0.9.0.
Changed in version 0.9.0: Allocation and recovery are byte-only. Callers create typed views and carry metadata separately;
seal()takes no payload argument.Methods
allocate_bytes(nbytes, *[, alignment])Allocate writable bytes within this unit; return a lifetime-owned view.
seal()Publish this unit's byte extent and return an opaque immutable ticket.
- allocate_bytes(nbytes: int, *, alignment: int = 64) memoryview[int][source]¶
Allocate writable bytes within this unit; return a lifetime-owned view.
- Parameters:
nbytes – Positive byte extent.
alignment – Power-of-two address alignment.
- Returns:
Writable memoryview, e.g.
data = unit.allocate_bytes(128). Callers create typed views over these bytes and retain those views for as long as they are in use, including asynchronous transfers.
Added in version 0.9.0.
- seal() _ArenaAllocationTicket[source]¶
Publish this unit’s byte extent and return an opaque immutable ticket.
- Returns:
Ticket for all allocated bytes and alignment padding, e.g.
ticket = unit.seal(). Send application metadata beside it, not inside it. Any number of serialized copies refer to the same single caller claim. Explicitly discard unread tickets; delivery failure and GC do not release their independent in-transit hold.- Raises:
RuntimeError – The reservation is already sealed or aborted.
Added in version 0.9.0.
Changed in version 0.9.0: Takes no payload argument; the ticket describes bytes only.