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