Creates an empty data buffer of a specified size.


init(capacity: Int)



The size of the data.


This initializer doesn’t necessarily allocate the requested memory right away. Data allocates additional memory as needed, so capacity simply establishes the initial capacity. When it does allocate the initial memory, though, it allocates the specified amount.

This method sets the count of the data to 0.

If the capacity specified in capacity is greater than four memory pages in size, this may round the amount of requested memory up to the nearest full page.

See Also

Creating Populated Data


Creates an empty data buffer.


Creates a new instance of a collection containing the elements of a sequence.

init<SourceType>(buffer: UnsafeBufferPointer<SourceType>)

Creates a data buffer with copied memory content using a buffer pointer.

init<SourceType>(buffer: UnsafeMutableBufferPointer<SourceType>)

Creates a data buffer with copied memory content using a mutable buffer pointer.

init(bytes: UnsafeRawPointer, count: Int)

Creates data with copied memory content.

init(bytesNoCopy: UnsafeMutableRawPointer, count: Int, deallocator: Data.Deallocator)

Creates a data buffer with memory content without copying the bytes.

init(count: Int)

Creates a new data buffer with the specified count of zeroed bytes.