Instance Methodswift 6.0.1Swift
bindMemory(to:)
Binds this buffer slice’s memory to the specified type and returns a typed buffer of the bound memory.
@discardableResult func bindMemory<T>(to type: T.Type) -> UnsafeBufferPointer<T>
Parameters
- type
The type
T
to bind the memory to.
Returns
A typed buffer of the newly bound memory. The memory in this region is bound to T
, but has not been modified in any other way. The typed buffer references self.count / MemoryLayout<T>.stride
instances of T
.
Use the bindMemory(to:)
method to bind the memory referenced by this buffer slice to the type T
. The memory must be uninitialized or initialized to a type that is layout compatible with T
. If the memory is uninitialized, it is still uninitialized after being bound to T
.
Other members in extension
Instance members
func assumingMemoryBound<T>(to: T.Type
) -> UnsafeBufferPointer<T> Returns a typed buffer to the memory referenced by this buffer slice, assuming that the memory is already bound to the specified type.
func load<T>(fromByteOffset: Int, as: T.Type
) -> T Returns a new instance of the given type, read from the specified offset into the buffer pointer slice’s raw memory.
func loadUnaligned<T>(fromByteOffset: Int, as: T.Type
) -> T func loadUnaligned<T>(fromByteOffset: Int, as: T.Type
) -> T Returns a new instance of the given type, read from the specified offset into the buffer pointer slice’s raw memory.
func withMemoryRebound<T, Result, E>(to: T.Type, (UnsafeBufferPointer<T>)
throws Executes the given closure while temporarily binding the buffer slice to instances of type
T
.