Skip to main content

Mojo function

sizeof

sizeof[type: AnyType, target: target = _current_target()]() -> Int

Returns the size of (in bytes) of the type.

Example:

from sys.info import sizeof
def main():
    print(
        sizeof[UInt8]() == 1,
        sizeof[UInt16]() == 2,
        sizeof[Int32]() == 4,
        sizeof[Float64]() == 8,
        sizeof[
            SIMD[DType.uint8, 4]
        ]() == 4,
    )

Note: align_of is in same module.

Parameters:

  • type (AnyType): The type in question.
  • target (target): The target architecture.

Returns:

Int: The size of the type in bytes.

sizeof[dtype: DType, target: target = _current_target()]() -> Int

Returns the size of (in bytes) of the dtype.

Parameters:

  • dtype (DType): The DType in question.
  • target (target): The target architecture.

Returns:

Int: The size of the dtype in bytes.

Was this page helpful?