struct
UnsafePointer
<
Pointee
>
Inheritance |
CVarArg, Comparable, CustomDebugStringConvertible, CustomPlaygroundQuickLookable, CustomReflectable, Equatable, Hashable, Strideable
View Protocol Hierarchy →
|
---|---|
Associated Types |
|
Import |
|
Initializers
Converts from UnsafeMutablePointer
to an UnsafePointer
of the same Pointee
.
Declaration
init
(
_
other
:
UnsafeMutablePointer
<
Pointee
>
)
Creates an UnsafePointer
from another UnsafePointer
.
Declaration
init
(
_
other
:
UnsafePointer
<
Pointee
>
)
Converts from an opaque pointer to a typed pointer.
Returns nil
if from
is nil
.
Declaration
init
?(
_
from
:
OpaquePointer
?)
Converts from UnsafeMutablePointer
to an UnsafePointer
of the same Pointee
.
Returns nil if from
is nil.
Declaration
init
?(
_
other
:
UnsafeMutablePointer
<
Pointee
>
?)
Creates an UnsafePointer
from another UnsafePointer
.
Returns nil
if other
is nil
.
Declaration
init
?(
_
other
:
UnsafePointer
<
Pointee
>
?)
Creates an UnsafePointer
with a given pattern of bits.
Returns nil
if bitPattern
is zero.
Declaration
init
?(
bitPattern
:
Int
)
Creates an UnsafePointer
with a given pattern of bits.
Returns nil
if bitPattern
is zero.
Declaration
init
?(
bitPattern
:
UInt
)
Instance Variables
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
}
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
}
A textual representation of the pointer, suitable for debugging.
Declaration
var
debugDescription
:
String
{
get
}
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
}
Accesses the Pointee
instance referenced by self
.
Precondition: the pointee has been initialized with an instance of
type Pointee
.
Declaration
var
pointee
:
Pointee
{
get
}
Subscripts
Accesses the pointee at self + i
.
Precondition: the pointee at self + i
is initialized.
Declaration
subscript
(
i
:
Int
) -
>
Pointee
{
get
}
Instance Methods
Rebinds memory at self
to type T
with capacity to hold count
adjacent T
values while executing the body
closure.
After executing the closure, rebinds memory back to Pointee
.
Precondition: Type 'T' is layout compatible with type 'Pointee'.
Precondition: The memory self..<self + count * MemoryLayout<T>.stride
is bound to Pointee
.
Accessing UnsafePointer<T>.pointee
requires that the memory be "bound" to
type T
. A memory location may only be bound to one type at a time, so
accessing the same memory as an unrelated type without first rebinding the
memory is undefined. self
may not be accessed within the body
closure
because memory is no longer bound to Pointee
while it executes. The
closure's UnsafePointer<T>
argument must not escape the closure because memory
is only temporarily bound to T
.
To persistently bind this memory to a different type, first obtain a
raw pointer to the memory, then invoke the bindMemory
API:
UnsafeRawPointer(typedPointer).bindMemory(to:capacity:)
.
Declaration
func
withMemoryRebound
<
T
,
Result
>
(
to
:
T
.
Type
,
capacity
count
:
Int
,
_
body
: (
UnsafePointer
<
T
>
)
throws
-
>
Result
)
rethrows
-
>
Result
A raw pointer for accessing data of type
Pointee
. This type provides no automated memory management, and therefore must be handled with great care to ensure safety.Instances must be aligned to
MemoryLayout<Pointee>.alignment
, i.e.(UnsafePointer<Int8>(self) - nil) % MemoryLayout<Pointee>.alignment == 0
The memory referenced by an instance 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.