Skip to main content

Mojo function

stack_allocation

stack_allocation[count: Int, dtype: DType, /, alignment: Int = align_of[dtype](), address_space: AddressSpace = AddressSpace.GENERIC]() -> UnsafePointer[Scalar[dtype], origin_of(), 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:

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

stack_allocation[count: Int, type: UnknownDestructibility, /, name: Optional[StaticString] = None, alignment: Int = align_of[type](), address_space: AddressSpace = AddressSpace.GENERIC]() -> UnsafePointer[type, origin_of(), 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 (UnknownDestructibility): The data type of each element.
  • name (Optional): 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:

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

Was this page helpful?