withTemporaryAllocation(of:capacity:_:)
Provides scoped access to an output span of the specified type and capacity.
Declaration
func withTemporaryAllocation<T, R, E>(of type: T.Type, capacity: Int, _ body: @_lifetime(0: copy 0) (inout OutputSpan<T>) throws(E) -> R) throws(E) -> R where E : Error, T : ~Copyable, R : ~CopyableParameters
- type:
The type of the elements in the buffer being temporarily allocated.
- capacity:
The capacity of the output span being temporarily allocated.
- body:
A closure to invoke and to which the allocated output span should be passed.
Return Value
Whatever is returned by body.
Discussion
This function is useful for cheaply allocating storage for a sequence of values for a brief duration. Storage may be allocated on the heap or on the stack, depending on the required size and alignment.
When body is called, it is passed an empty OutputSpan. body may append or initialize elements in the output span. Any elements that have been initialized when body returns are deinitialized automatically, and deallocation is also automatic.
See Also
Memory Access
withUnsafePointer(to:_:)withUnsafePointer(to:_:)withUnsafeMutablePointer(to:_:)withUnsafeBytes(of:_:)withUnsafeMutableBytes(of:_:)withTemporaryAllocation(byteCount:alignment:_:)withUnsafeTemporaryAllocation(of:capacity:_:)withUnsafeTemporaryAllocation(byteCount:alignment:_:)swap(_:_:)exchange(_:with:)