Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Align

Returns an allocation size in bytes that factors in alignment.
Read time 1 minuteLast updated 11 days ago

Definition

  • Type: Method
  • Namespace: Unity.Collections
  • Assembly: UnityEngine.ManagedKernelModule

Align(int, int)

Returns an allocation size in bytes that factors in alignment.
public static int Align(int size, int alignmentPowerOfTwo)

Parameters

size

The size to align.

alignmentPowerOfTwo

A non-zero, positive power of two.

Returns

Type

Description

intThe smallest integer that is greater than or equal to
size
and is a multiple of
alignmentPowerOfTwo
.

Examples

// 55 aligned to 16 is 64.int size = CollectionHelper.Align(55, 16);

Align(long, int)

Returns an allocation size in bytes that factors in alignment.
public static long Align(long size, int alignmentPowerOfTwo)

Parameters

size

The size to align.

alignmentPowerOfTwo

A non-zero, positive power of two.

Returns

Type

Description

longThe smallest integer that is greater than or equal to
size
and is a multiple of
alignmentPowerOfTwo
.

Examples

// 55 aligned to 16 is 64.long size = CollectionHelper.Align(55, 16);

Align(ulong, ulong)

Returns an allocation size in bytes that factors in alignment.
public static ulong Align(ulong size, ulong alignmentPowerOfTwo)

Parameters

size

The size to align.

alignmentPowerOfTwo

A non-zero, positive power of two.

Returns

Type

Description

ulongThe smallest integer that is greater than or equal to
size
and is a multiple of
alignmentPowerOfTwo
.

Examples

// 55 aligned to 16 is 64.ulong size = CollectionHelper.Align(55, 16);