UnsafePointer

struct UnsafePointer<T>

A pointer to an object of type T. This type provides no automated memory management, and therefore the user must take care to allocate and free memory appropriately.

The pointer can be in one of the following states:

  • memory is not allocated (for example, pointer is null, or memory has been deallocated previously);

  • memory is allocated, but value has not been initialized;

  • memory is allocated and value is initialized.

Inheritance BidirectionalIndexType, CVarArgType, Comparable, DebugPrintable, Equatable, ForwardIndexType, Hashable, NilLiteralConvertible, RandomAccessIndexType, Reflectable, Strideable, _BidirectionalIndexType, _Comparable, _ForwardIndexType, _Incrementable, _PointerType, _RandomAccessIndexType, _Strideable View Protocol Hierarchy →
Import import Swift

Initializers

init()

Construct a null pointer.

Declaration

init()
init(_: COpaquePointer)

Convert from an opaque C pointer to a typed pointer

This is a fundamentally unsafe conversion.

Declaration

init(_ other: COpaquePointer)
init<U>(_: UnsafeMutablePointer<U>)

Convert from an UnsafeMutablePointer of a different type.

This is a fundamentally unsafe conversion.

Declaration

init<U>(_ from: UnsafeMutablePointer<U>)
init<U>(_: UnsafePointer<U>)

Convert from a UnsafePointer of a different type.

This is a fundamentally unsafe conversion.

Declaration

init<U>(_ from: UnsafePointer<U>)
init(bitPattern: UWord)

Construct an UnsafePointer from a given address in memory.

This is a fundamentally unsafe conversion.

Declaration

init(bitPattern: UWord)
init(bitPattern: Word)

Construct an UnsafePointer from a given address in memory.

This is a fundamentally unsafe conversion.

Declaration

init(bitPattern: Word)
init(nilLiteral:)

Create an instance initialized with nil.

Declaration

init(nilLiteral: ())

Instance Variables

var debugDescription: String

A textual representation of self, suitable for debugging.

Declaration

var debugDescription: String { get }
var hashValue: Int

The hash value.

Axiom: x == y implies x.hashValue == y.hashValue

Note: the hash value is not guaranteed to be stable across different invocations of the same program. Do not persist the hash value across program runs.

Declaration

var hashValue: Int { get }
var memory: T

Access the underlying raw memory, getting and setting values.

Declaration

var memory: T { get }

Subscripts

subscript(_: Int)

Declaration

subscript(i: Int) -> T { get }

Instance Methods

func advancedBy(_:)

Return self offset by n steps.

Returns: If n > 0, the result of applying successor to self n times. If n < 0, the result of applying predecessor to self -n times. Otherwise, self.

Complexity: O(1)

Declaration

func advancedBy(n: Int) -> UnsafePointer<T>
func distanceTo(_:)

Return the minimum number of applications of successor or predecessor required to reach other from self.

Complexity: O(1).

Declaration

func distanceTo(x: UnsafePointer<T>) -> Int
func encode()

Transform self into a series of machine words that can be appropriately interpreted by C varargs

Declaration

func encode() -> [Word]
func getMirror()

Returns a mirror that reflects self.

Declaration

func getMirror() -> MirrorType
func predecessor()

Returns the previous consecutive value before self.

Requires: the previous value is representable.

Declaration

func predecessor() -> UnsafePointer<T>
func successor()

Returns the next consecutive value after self.

Requires: the next value is representable.

Declaration

func successor() -> UnsafePointer<T>