MemoryLayout

enum MemoryLayout<T>

The memory layout of a type, describing its size, stride, and alignment.

Import import Swift

Static Variables

static var alignment: Int

The default memory alignment of T.

Declaration

static var alignment: Int { get }
static var size: Int

The contiguous memory footprint of T.

Does not include any dynamically-allocated or "remote" storage. In particular, MemoryLayout<T>.size, when T is a class type, is the same regardless of how many stored properties T has.

Declaration

static var size: Int { get }
static var stride: Int

The number of bytes from the start of one instance of T to the start of the next in an Array<T>.

This is the same as the number of bytes moved when an UnsafePointer<T> is incremented. T may have a lower minimal alignment that trades runtime performance for space efficiency. The result is always positive.

Declaration

static var stride: Int { get }

Static Methods

static func alignment(ofValue:)

Returns the default memory alignment of T.

Declaration

static func alignment(ofValue _: T) -> Int
static func size(ofValue:)

Returns the contiguous memory footprint of T.

Does not include any dynamically-allocated or "remote" storage. In particular, MemoryLayout.size(ofValue: x), when x is a class instance, is the same regardless of how many stored properties T has.

Declaration

static func size(ofValue _: T) -> Int
static func stride(ofValue:)

Returns the number of bytes from the start of one instance of T to the start of the next in an Array<T>.

This is the same as the number of bytes moved when an UnsafePointer<T> is incremented. T may have a lower minimal alignment that trades runtime performance for space efficiency. The result is always positive.

Declaration

static func stride(ofValue _: T) -> Int