IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /docs/manual/basics.md). For the complete Mojo documentation index, see llms.txt.
Skip to main content
Version: Nightly
For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

Alignment

struct Alignment

The byte alignment of a memory allocation.

Implemented traits​

AnyType, Copyable, Deinitable, ImplicitlyCopyable, Movable, RegisterPassable, TrivialRegisterPassable, Writable

Methods​

of​

static def of[T: AnyType, /]() -> Self

Returns the natural alignment of T.

Parameters:

  • ​T (AnyType): The type whose align_of to use.

Returns:

Self: An Alignment of align_of[T]() bytes.

of_bytes​

static def of_bytes[n: Int, /]() -> Self

Returns an alignment of exactly n bytes.

Constraints:

n must be a power of two.

Parameters:

  • ​n (Int): The byte alignment.

Returns:

Self: An Alignment of n bytes.

bytes​

def bytes(self) -> Int

Returns the byte alignment.

Returns:

Int: The byte alignment.

write_to​

def write_to(self, mut writer: T)

Writes a human-readable representation of this alignment to writer.

Args:

  • ​writer (T): The writer to write to.