# AlignOf<T>()

> Retrieves the minimum memory alignment requirement for a specified struct type.

## Definition

* **Type:** Method
* **Namespace:** [Unity.Collections.LowLevel.Unsafe](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe.md)
* **Assembly:** UnityEngine.CoreModule

```csharp
public static int AlignOf<T>() where T : struct
```

### Returns

| Type                                                       | Description                                                         |
| ---------------------------------------------------------- | ------------------------------------------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | The alignment size in bytes required for the specified struct type. |

### Remarks

The `AlignOf` method calculates the minimum alignment required for a struct type in memory. This is crucial for ensuring the proper alignment of data structures, which can improve access speed and comply with hardware requirements.

Proper alignment can prevent performance penalties by avoiding misaligned data access, which might require multiple memory accesses. This function is particularly useful when you're implementing custom memory allocations or interop scenarios where data alignment is critical.

```csharp
using System;
using Unity.Collections.LowLevel.Unsafe;
using System.Runtime.InteropServices;
using UnityEngine;

[StructLayout(LayoutKind.Sequential)]
struct ExampleStruct
{
    public byte ByteValue;  // 1 byte
    public int IntValue;    // 4 bytes
    public byte AnotherByte; // 1 byte
}

public class StructSizeAndAlignment : MonoBehaviour
{
    void Start()
    {
        // Calculate size and alignment for ExampleStruct
        int size = UnsafeUtility.SizeOf<ExampleStruct>();
        int alignment = UnsafeUtility.AlignOf<ExampleStruct>();

        Debug.Log($"Size of ExampleStruct: {size} bytes");
        Debug.Log($"Alignment requirement of ExampleStruct: {alignment} bytes");
    }
}
```

Additional Resources: [UnsafeUtility.SizeOf](/engine/6000.6/script-reference/unity/collections/lowlevel/unsafe/unsafeutility/sizeof.md).
