UnsafeRawPointer

struct UnsafeRawPointer

A raw pointer for accessing untyped data. This provides no automatic memory management, no type safety, and no alignment guarantees. This implements Strideable to provide a view of byte-addressable memory.

Inheritance Comparable, CustomDebugStringConvertible, CustomPlaygroundQuickLookable, CustomReflectable, Equatable, Hashable, Strideable View Protocol Hierarchy →
Import import Swift

Initializers

init(_: OpaquePointer)

Converts an opaque pointer to an UnsafeRawPointer.

Declaration

init(_ other: OpaquePointer)
init(_: UnsafeMutableRawPointer)

Converts an UnsafeMutableRawPointer to an UnsafeRawPointer.

Declaration

init(_ other: UnsafeMutableRawPointer)
init(_: UnsafeRawPointer)

Creates an UnsafeRawPointer from another UnsafeRawPointer.

Declaration

init(_ other: UnsafeRawPointer)
init<T>(_: AutoreleasingUnsafeMutablePointer<T>)

Convert other AutoreleasingUnsafeMutablePointer.

Declaration

init<T>(_ other: AutoreleasingUnsafeMutablePointer<T>)
init<T>(_: UnsafeMutablePointer<T>)

Converts an UnsafeMutablePointer to an UnsafeRawPointer.

Declaration

init<T>(_ other: UnsafeMutablePointer<T>)
init<T>(_: UnsafePointer<T>)

Converts an UnsafePointer to an UnsafeRawPointer.

Declaration

init<T>(_ other: UnsafePointer<T>)
init?(_: OpaquePointer?)

Converts an opaque pointer to an UnsafeRawPointer.

Returns nil if from is nil.

Declaration

init?(_ other: OpaquePointer?)
init?(_: UnsafeMutableRawPointer?)

Converts an UnsafeMutableRawPointer to an UnsafeRawPointer.

Returns nil if other is nil.

Declaration

init?(_ other: UnsafeMutableRawPointer?)
init?(_: UnsafeRawPointer?)

Creates an UnsafeRawPointer from another UnsafeRawPointer.

Returns nil if other is nil.

Declaration

init?(_ other: UnsafeRawPointer?)
init?<T>(_: AutoreleasingUnsafeMutablePointer<T>?)

Convert other AutoreleasingUnsafeMutablePointer.

Returns nil if other is nil.

Declaration

init?<T>(_ other: AutoreleasingUnsafeMutablePointer<T>?)
init?<T>(_: UnsafeMutablePointer<T>?)

Converts an UnsafeMutablePointer to an UnsafeRawPointer.

Returns nil if other is nil.

Declaration

init?<T>(_ other: UnsafeMutablePointer<T>?)
init?<T>(_: UnsafePointer<T>?)

Converts an UnsafePointer to an UnsafeRawPointer.

Returns nil if other is nil.

Declaration

init?<T>(_ other: UnsafePointer<T>?)
init?(bitPattern: Int)

Converts a pattern of bits to an UnsafeRawPointer.

Returns nil if bitPattern is zero.

Declaration

init?(bitPattern: Int)
init?(bitPattern: UInt)

Converts a pattern of bits to an UnsafeRawPointer.

Returns nil if bitPattern is zero.

Declaration

init?(bitPattern: UInt)

Instance Variables

var customMirror: Mirror

The custom mirror for this instance.

If this type has value semantics, the mirror should be unaffected by subsequent mutations of the instance.

Declaration

var customMirror: Mirror { get }
var customPlaygroundQuickLook: PlaygroundQuickLook

A custom playground Quick Look for this instance.

If this type has value semantics, the PlaygroundQuickLook instance should be unaffected by subsequent mutations.

Declaration

var customPlaygroundQuickLook: PlaygroundQuickLook { get }
var debugDescription: String

A textual representation of the pointer, suitable for debugging.

Declaration

var debugDescription: String { get }
var hashValue: Int

The pointer's hash value.

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 }

Instance Methods

func advanced(by:)

Returns self + n.

Declaration

func advanced(by n: Int) -> UnsafeRawPointer
func assumingMemoryBound(_:)

Converts from an UnsafeRawPointer to UnsafePointer<T> given that the region of memory starting at self is already bound to type T.

Precondition: The memory is bound to 'T' starting at self for some unspecified capacity.

Warning: Accessing memory via the returned pointer is undefined if the if the memory has not been bound to T.

Declaration

func assumingMemoryBound<T>(to: T.Type) -> UnsafePointer<T>
func bindMemory(to:capacity:)

Binds the allocated memory to type T and returns an UnsafePointer<T> to the bound memory at self.

Precondition: The memory is uninitialized. Postcondition: The memory is bound to 'T' starting at self continuing through self + count * MemoryLayout<T>.stride Warning: A memory location may only be bound to one type at a time. The behavior of accessing memory as type U while it is bound to an unrelated type T is undefined.

Declaration

func bindMemory<T>(to type: T.Type, capacity count: Int) -> UnsafePointer<T>
func deallocate(_:alignedTo:)

Deallocates uninitialized memory allocated for bytes number of bytes with alignedTo alignment.

Precondition: The memory is not initialized. Postcondition: The memory has been deallocated.

Declaration

func deallocate(bytes: Int, alignedTo: Int)
func distance(to:)

Returns x - self.

Declaration

func distance(to x: UnsafeRawPointer) -> Int
func load(fromByteOffset:as:)

Reads raw bytes from memory at self + offset and constructs a value of type T.

Precondition: The underlying pointer plus offset is properly aligned for accessing T.

Precondition: The memory is initialized to a value of some type, U, such that T is layout compatible with U.

Declaration

func load<T>(fromByteOffset offset: Int = default, as type: T.Type) -> T