<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/MemoryLayout",
  "metadataVersion" : "0.1.0",
  "role" : "Enumeration",
  "symbol" : {
    "kind" : "Enumeration",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s12MemoryLayoutO"
  },
  "title" : "MemoryLayout"
}
-->

# MemoryLayout

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

```
@frozen enum MemoryLayout<T> where T : ~Copyable, T : ~Escapable
```

## Overview

You can use `MemoryLayout` as a source of information about a type when
allocating or binding memory using raw pointers. The following example
declares a `Point` type with `x` and `y` coordinates and a Boolean
`isFilled` property.

```
struct Point {
    let x: Double
    let y: Double
    let isFilled: Bool
}
```

The size, stride, and alignment of the `Point` type are accessible as
static properties of `MemoryLayout<Point>`.

```
// MemoryLayout<Point>.size == 17
// MemoryLayout<Point>.stride == 24
// MemoryLayout<Point>.alignment == 8
```

Always use a multiple of a type’s `stride` instead of its `size` when
allocating memory or accounting for the distance between instances in
memory. This example allocates uninitialized raw memory with space
for four instances of `Point`.

```
let count = 4
let pointPointer = UnsafeMutableRawPointer.allocate(
        byteCount: count * MemoryLayout<Point>.stride,
        alignment: MemoryLayout<Point>.alignment)
```

## Topics

### Accessing the Layout of a Type

Use these static properties to access a type’s layout. For example, the size of a
`Double` instance is `MemoryLayout<Double>.size`.

[`size`](/documentation/Swift/MemoryLayout/size)

The contiguous memory footprint of `T`, in bytes.

[`alignment`](/documentation/Swift/MemoryLayout/alignment)

The default memory alignment of `T`, in bytes.

[`stride`](/documentation/Swift/MemoryLayout/stride)

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>`.

### Accessing the Layout of a Value

Pass an instance to these static methods to acess the layout for that instance’s
type.

[`stride(ofValue:)`](/documentation/Swift/MemoryLayout/stride(ofValue:))

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>`.

[`size(ofValue:)`](/documentation/Swift/MemoryLayout/size(ofValue:))

Returns the contiguous memory footprint of the given instance.

[`alignment(ofValue:)`](/documentation/Swift/MemoryLayout/alignment(ofValue:))

Returns the default memory alignment of `T`.

### Querying Type Properties

[`offset(of:)`](/documentation/Swift/MemoryLayout/offset(of:))

Returns the offset of an inline stored property within a type’s in-memory
representation.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)