Instance Methodswift 6.0.1Swift
moveInitializeMemory(as:fromContentsOf:)
Moves every element of an initialized source buffer into the uninitialized memory referenced by this buffer, leaving the source memory uninitialized and this buffer’s memory initialized.
@discardableResult func moveInitializeMemory<T>(as type: T.Type, fromContentsOf source: UnsafeMutableBufferPointer<T>) -> UnsafeMutableBufferPointer<T> where T : ~Copyable
Parameters
Returns
A typed buffer referencing the initialized elements. The returned buffer references memory starting at the same base address as this buffer, and its count is equal to source.count
.
When calling the moveInitializeMemory(as:fromContentsOf:)
method, the memory referenced by the buffer must be uninitialized, or initialized to a trivial type. The buffer must reference enough memory to store source.count
elements, and its baseAddress
must be properly aligned for accessing C.Element
. After the method returns, the memory referenced by the returned buffer is initialized and the memory region underlying source
is uninitialized.
This method initializes the buffer with the contents of source
until source
is exhausted. After calling initializeMemory(as:fromContentsOf:)
, the memory referenced by the returned UnsafeMutableBufferPointer
instance is bound to the type T
and is initialized. This method does not change the binding state of the unused portion of the buffer, if any.
Other members in extension
Typealiases
Type members
init(UnsafeMutableRawBufferPointer
) Creates a new buffer over the same memory as the given buffer.
init<T>(UnsafeMutableBufferPointer<T>
) Creates a raw buffer over the contiguous bytes in the given typed buffer.
init(mutating: UnsafeRawBufferPointer
) Creates a new mutable buffer over the same memory as the given buffer.
init(rebasing: Slice<UnsafeMutableRawBufferPointer>
) Creates a raw buffer over the same memory as the given raw buffer slice, with the indices rebased to zero.
init(start: UnsafeMutableRawPointer?, count: Int
) Creates a buffer over the specified number of contiguous bytes starting at the given pointer.
static func allocate(byteCount: Int, alignment: Int
) -> UnsafeMutableRawBufferPointer Allocates uninitialized memory with the specified size and alignment.
Show obsolete interfaces (1)
Hide obsolete interfaces
Instance members
var baseAddress: UnsafeMutableRawPointer?
A pointer to the first byte of the buffer.
var count: Int
The number of bytes in the buffer.
var debugDescription: String
A textual representation of the buffer, suitable for debugging.
var endIndex: UnsafeMutableRawBufferPointer.Index
The “past the end” position—that is, the position one greater than the last valid subscript argument.
var indices: UnsafeMutableRawBufferPointer.Indices
var startIndex: UnsafeMutableRawBufferPointer.Index
Always zero, which is the index of the first byte in a nonempty buffer.
subscript(Range<Int>
) -> UnsafeMutableRawBufferPointer.SubSequence Accesses the bytes in the specified memory region.
subscript(Int
) -> UnsafeMutableRawBufferPointer.Element Accesses the byte at the given offset in the memory region as a
UInt8
value.func assumingMemoryBound<T>(to: T.Type
) -> UnsafeMutableBufferPointer<T> Returns a typed buffer to the memory referenced by this buffer, assuming that the memory is already bound to the specified type.
func bindMemory<T>(to: T.Type
) -> UnsafeMutableBufferPointer<T> Binds this buffer’s memory to the specified type and returns a typed buffer of the bound memory.
func copyBytes<C>(from: C
) Copies from a collection of
UInt8
into this buffer’s memory.func copyMemory(from: UnsafeRawBufferPointer
) Copies the bytes from the given buffer to this buffer’s memory.
func deallocate(
) Deallocates the memory block previously allocated at this buffer pointer’s base address.
func initializeMemory<S>(as: S.Element.Type, from: S
) -> (unwritten: S.Iterator, initialized: UnsafeMutableBufferPointer<S.Element>) Initializes the buffer’s memory with the given elements, binding the initialized memory to the elements’ type.
func initializeMemory<C>(as: C.Element.Type, fromContentsOf: C
) -> UnsafeMutableBufferPointer<C.Element> Initializes the buffer’s memory with every element of the source, binding the initialized memory to the elements’ type.
func initializeMemory<T>(as: T.Type, repeating: T
) -> UnsafeMutableBufferPointer<T> Initializes the memory referenced by this buffer with the given value, binds the memory to the value’s type, and returns a typed buffer of the initialized memory.
func load<T>(fromByteOffset: Int, as: T.Type
) -> T Returns a new instance of the given type, read from the buffer pointer’s raw memory at the specified byte offset.
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, constructed from the raw memory at the specified offset.
func makeIterator(
) -> UnsafeMutableRawBufferPointer.Iterator Returns an iterator over the bytes of this sequence.
func moveInitializeMemory<T>(as: T.Type, fromContentsOf: Slice<UnsafeMutableBufferPointer<T>>
) -> UnsafeMutableBufferPointer<T> Moves every element of an initialized source buffer slice into the uninitialized memory referenced by this buffer, leaving the source memory uninitialized and this buffer’s memory initialized.
func storeBytes<T>(of: T, toByteOffset: Int, as: T.Type
) Stores a value’s bytes into the buffer pointer’s raw memory at the specified byte offset.
func swapAt(Int, Int
) Exchanges the byte values at the specified indices in this buffer’s memory.
func withContiguousMutableStorageIfAvailable<R>((inout UnsafeMutableBufferPointer<UnsafeMutableRawBufferPointer.Element>) throws -> R
) rethrows -> R? func withContiguousStorageIfAvailable<R>((UnsafeBufferPointer<UnsafeMutableRawBufferPointer.Element>) throws -> R
) rethrows -> R? func withMemoryRebound<T, E, Result>(to: T.Type, (UnsafeMutableBufferPointer<T>)
throws Executes the given closure while temporarily binding the buffer to instances of type
T
.