struct
UnsafePointer
This is a pointer type that can point to any generic value that is movable.
Parameters
- T (
AnyType
): The type the pointer points to. - address_space (
AddressSpace
): The address space associated with the UnsafePointer allocated memory.
Aliases
type = T
:
Fields
- address (
pointer<:trait<@stdlib::@builtin::@anytype::@AnyType> T, #lit.struct.extract<:@stdlib::@builtin::@int::@Int #lit.struct.extract<:@stdlib::@memory::@reference::@AddressSpace address_space, "_value">, "value">>
): The underlying pointer.
Implemented traits
AnyType
,
Boolable
,
CollectionElement
,
Comparable
,
Copyable
,
EqualityComparable
,
Intable
,
Movable
,
Stringable
Methods
__init__
__init__() -> Self
Create a null pointer.
Returns:
A null pointer.
__init__(value: pointer<:trait<_stdlib::_builtin::_anytype::_AnyType> T, #lit.struct.extract<:_stdlib::_builtin::_int::_Int #lit.struct.extract<:_stdlib::_memory::_reference::_AddressSpace address_space, "_value">, "value">>) -> Self
Create a pointer with the input value.
Args:
- value (
pointer<:trait<_stdlib::_builtin::_anytype::_AnyType> T, #lit.struct.extract<:_stdlib::_builtin::_int::_Int #lit.struct.extract<:_stdlib::_memory::_reference::_AddressSpace address_space, "_value">, "value">>
): The MLIR value of the pointer to construct with.
Returns:
The pointer.
__init__(value: Reference[T, is_mutable, lifetime, address_space]) -> Self
Create an unsafe UnsafePointer from a safe Reference.
Args:
- value (
Reference[T, is_mutable, lifetime, address_space]
): The input reference to construct with.
Returns:
The pointer.
__init__(*, address: Int) -> Self
Create an unsafe UnsafePointer from an address in an integer.
Args:
- address (
Int
): The address to construct the pointer with.
Returns:
The pointer.
__bool__
__bool__(self: Self) -> Bool
Return true if the pointer is non-null.
Returns:
Whether the pointer is null.
__getitem__
__getitem__(self: Self) -> ref [#lit.lifetime] T
Return a reference to the underlying data.
Returns:
A reference to the value.
__getitem__(self: Self, offset: Int) -> ref [#lit.lifetime] T
Return a reference to the underlying data, offset by the given index.
Args:
- offset (
Int
): The offset index.
Returns:
An offset reference.
__lt__
__lt__(self: Self, rhs: Self) -> Bool
Returns True if this pointer represents a lower address than rhs.
Args:
- rhs (
Self
): The value of the other pointer.
Returns:
True if this pointer represents a lower address and False otherwise.
__le__
__le__(self: Self, rhs: Self) -> Bool
Returns True if this pointer represents a lower than or equal address than rhs.
Args:
- rhs (
Self
): The value of the other pointer.
Returns:
True if this pointer represents a lower address and False otherwise.
__eq__
__eq__(self: Self, rhs: Self) -> Bool
Returns True if the two pointers are equal.
Args:
- rhs (
Self
): The value of the other pointer.
Returns:
True if the two pointers are equal and False otherwise.
__ne__
__ne__(self: Self, rhs: Self) -> Bool
Returns True if the two pointers are not equal.
Args:
- rhs (
Self
): The value of the other pointer.
Returns:
True if the two pointers are not equal and False otherwise.
__gt__
__gt__(self: Self, rhs: Self) -> Bool
Returns True if this pointer represents a higher address than rhs.
Args:
- rhs (
Self
): The value of the other pointer.
Returns:
True if this pointer represents a higher than or equal address and False otherwise.
__ge__
__ge__(self: Self, rhs: Self) -> Bool
Returns True if this pointer represents a higher than or equal address than rhs.
Args:
- rhs (
Self
): The value of the other pointer.
Returns:
True if this pointer represents a higher than or equal address and False otherwise.
__add__
__add__(self: Self, offset: Int) -> Self
Return a pointer at an offset from the current one.
Args:
- offset (
Int
): The offset index.
Returns:
An offset pointer.
__sub__
__sub__(self: Self, offset: Int) -> Self
Return a pointer at an offset from the current one.
Args:
- offset (
Int
): The offset index.
Returns:
An offset pointer.
__iadd__
__iadd__(inout self: Self, offset: Int)
Add an offset to this pointer.
Args:
- offset (
Int
): The offset index.
__isub__
__isub__(inout self: Self, offset: Int)
Subtract an offset from this pointer.
Args:
- offset (
Int
): The offset index.
alloc
static alloc(count: Int) -> Self
Allocate an array with default alignment.
Args:
- count (
Int
): The number of elements in the array.
Returns:
The pointer to the newly allocated array.
address_of
static address_of(arg: Reference[T, is_mutable, lifetime, address_space]) -> Self
Gets the address of the argument.
Args:
- arg (
Reference[T, is_mutable, lifetime, address_space]
): The value to get the address of.
Returns:
An UnsafePointer which contains the address of the argument.
free
free(self: Self)
Free the memory referenced by the pointer.
bitcast
bitcast[new_type: AnyType = T, /, address_space: AddressSpace = address_space](self: Self) -> UnsafePointer[$0, $1]
Bitcasts a UnsafePointer to a different type.
Parameters:
- new_type (
AnyType
): The target type. - address_space (
AddressSpace
): The address space of the result.
Returns:
A new UnsafePointer object with the specified type and the same address, as the original UnsafePointer.
offset
offset(self: Self, offset: Int) -> Self
Return a pointer at an offset from the current one.
Args:
- offset (
Int
): The offset index.
Returns:
An offset pointer.