Instance Methodswift 6.0.3Swift

initializeMemory(as:fromContentsOf:)

Initializes the buffer’s memory with every element of the source, binding the initialized memory to the elements’ type.

func initializeMemory<C>(as type: C.Element.Type, fromContentsOf source: C) -> UnsafeMutableBufferPointer<C.Element> where C : Collection

Parameters

type

The type of element to which this buffer’s memory will be bound.

source

A collection of elements to be used to initialize the buffer’s storage.

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 initializeMemory(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.

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 C.Element and is initialized. This method does not change the binding state of the unused portion of the buffer, if any.