Skip to content

Initializer

init(bytesNoCopy:count:deallocator:)

iOS 8.0+ iPadOS 8.0+ Mac Catalyst 8.0+ macOS 10.10+ tvOS 9.0+ watchOS 2.0+
Creates a data buffer with memory content without copying the bytes.
init(bytesNoCopy bytes: UnsafeMutableRawPointer, count: Int, deallocator: Data.Deallocator)

Parameters

bytes

A pointer to the bytes.

count

The size of the bytes.

deallocator

Specifies the mechanism to free the indicated buffer, or .none.

Discussion

If the result is mutated and is not a unique reference, then the Data will still follow copy-on-write semantics. In this case, the copy will use its own deallocator. Therefore, it is usually best to only use this initializer when you either enforce immutability with let or ensure that no other references to the underlying data are formed.