Skip to main content

Mojo function

stack_allocation

stack_allocation[count: Int, dtype: DType, /, alignment: Int = alignof[::DType,__mlir_type.!kgen.target]() if is_gpu() else 1, address_space: AddressSpace = AddressSpace(0)]() -> UnsafePointer[SIMD[dtype, 1], address_space=address_space]

Allocates data buffer space on the stack given a data type and number of elements.

Parameters:

  • count (Int): Number of elements to allocate memory for.
  • dtype (DType): The data type of each element.
  • alignment (Int): Address alignment of the allocated data.
  • address_space (AddressSpace): The address space of the pointer.

Returns:

A data pointer of the given type pointing to the allocated space.

stack_allocation[count: Int, type: AnyType, /, name: Optional[StringSlice[StaticConstantOrigin]] = Optional(None), alignment: Int = alignof[::AnyType,__mlir_type.!kgen.target]() if is_gpu() else 1, address_space: AddressSpace = AddressSpace(0)]() -> UnsafePointer[type, address_space=address_space]

Allocates data buffer space on the stack given a data type and number of elements.

Parameters:

  • count (Int): Number of elements to allocate memory for.
  • type (AnyType): The data type of each element.
  • name (Optional[StringSlice[StaticConstantOrigin]]): The name of the global variable (only honored in certain cases).
  • alignment (Int): Address alignment of the allocated data.
  • address_space (AddressSpace): The address space of the pointer.

Returns:

A data pointer of the given type pointing to the allocated space.

Was this page helpful?