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).

unsafe_stack_allocation

def unsafe_stack_allocation[count: Int, dtype: DType, /, alignment: Int = align_of[dtype](), address_space: AddressSpace = AddressSpace.GENERIC]() -> Pointer[Scalar[dtype], MutUntrackedOrigin, 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:

Pointer[Scalar[dtype], MutUntrackedOrigin, address_space=address_space]: A data pointer of the given type pointing to the allocated space.

def unsafe_stack_allocation[count: Int, type: AnyType, /, name: Optional[StringSlice[ImmStaticOrigin]] = None, alignment: Int = Int((get_alignof type, _current_target())), address_space: AddressSpace = AddressSpace.GENERIC]() -> Pointer[type, MutUntrackedOrigin, 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[ImmStaticOrigin]]): 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:

Pointer[type, MutUntrackedOrigin, address_space=address_space]: A data pointer of the given type pointing to the allocated space.