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).
size_of
def size_of[type: AnyType, target: CompilationTarget = CompilationTarget.current()]() -> Int
Returns the size of (in bytes) of the type.
The size includes any padding required by the type's alignment, so it is
always a multiple of align_of[type]() and always matches the stride
between adjacent elements of an array of the type.
Example:
from std.sys.info import size_of
def main() raises:
print(
size_of[UInt8]() == 1,
size_of[UInt16]() == 2,
size_of[Int32]() == 4,
size_of[Float64]() == 8,
size_of[
SIMD[.uint8, 4]
]() == 4,
)
Note: align_of is in same module.
Parameters:
- type (
AnyType): The type in question. - target (
CompilationTarget): The target architecture.
Returns:
Int: The size of the type in bytes.
def size_of[dtype: DType, target: CompilationTarget = CompilationTarget.current()]() -> Int
Returns the size of (in bytes) of the dtype.
Parameters:
- dtype (
DType): The DType in question. - target (
CompilationTarget): The target architecture.
Returns:
Int: The size of the dtype in bytes.