Type Method


Returns the contiguous memory footprint of the given instance.


static func size(ofValue value: T) -> Int



A value representative of the type to describe.

Return Value

The size, in bytes, of the given value’s type.


The result does not include any dynamically allocated or out of line storage. In particular, pointers and class instances all have the same contiguous memory footprint, regardless of the size of the referenced data.

When you have a type instead of an instance, use the MemoryLayout<T>.size static property instead.

let x: Int = 100

// Finding the size of a value's type
let s = MemoryLayout.size(ofValue: x)
// s == 8

// Finding the size of a type directly
let t = MemoryLayout<Int>.size
// t == 8

See Also

Accessing the Layout of a Value

static func stride(ofValue: T) -> Int

Returns the number of bytes from the start of one instance of T to the start of the next when stored in contiguous memory or in an Array<T>.

static func alignment(ofValue: T) -> Int

Returns the default memory alignment of T.