UnsafeMutablePointer

struct UnsafeMutablePointer<Memory>

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

The pointer should be aligned to alignof(Memory.self).

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, CustomDebugStringConvertible, Equatable, ForwardIndexType, Hashable, NilLiteralConvertible, RandomAccessIndexType, Strideable, _Incrementable, _PointerType, _RandomAccessAmbiguity, _Reflectable, _Strideable View Protocol Hierarchy →
Associated Types
Distance = Int
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: Int)

Construct an UnsafeMutablePointer from a given address in memory.

This is a fundamentally unsafe conversion.

Declaration

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

Construct an UnsafeMutablePointer from a given address in memory.

This is a fundamentally unsafe conversion.

Declaration

init(bitPattern: UInt)
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: Memory

Access the underlying raw memory, getting and setting values.

Declaration

var memory: Memory { get set }

Subscripts

subscript(_: Int)

Declaration

subscript(i: Int) -> Memory { get nonmutating set }

Static Methods

static func alloc(_:)

Allocate memory for num objects of type Memory.

Postcondition: The memory is allocated, but not initialized.

Declaration

static func alloc(num: Int) -> UnsafeMutablePointer<Memory>

Instance Methods

func advancedBy(_:)

Declaration

func advancedBy(n: Int) -> UnsafeMutablePointer<Memory>

Declared In

UnsafeMutablePointer, RandomAccessIndexType, BidirectionalIndexType, _RandomAccessAmbiguity, ForwardIndexType
func advancedBy(_:limit:)

Declaration

func advancedBy(n: UnsafeMutablePointer<Memory>.Distance, limit: UnsafeMutablePointer<Memory>) -> UnsafeMutablePointer<Memory>

Declared In

RandomAccessIndexType, BidirectionalIndexType, ForwardIndexType
func assignBackwardFrom(_:count:)

Assign from count values beginning at source into initialized memory, proceeding from the last value to the first. Use this for assigning ranges into later memory that may overlap with the source range.

Requires: Either source precedes self or follows self + count.

Declaration

func assignBackwardFrom(source: UnsafeMutablePointer<Memory>, count: Int)
func assignFrom(_:count:)

Assign from count values beginning at source into initialized memory, proceeding from the first element to the last.

Declaration

func assignFrom(source: UnsafeMutablePointer<Memory>, count: Int)
func dealloc(_:)

Deallocate num objects.

num: Number of objects to deallocate. Should match exactly the value that was passed to alloc() (partial deallocations are not possible).

Precondition: The memory is not initialized.

Postcondition: The memory has been deallocated.

Declaration

func dealloc(num: Int)
func destroy()

Destroy the object the pointer points to.

Precondition: The memory is initialized.

Postcondition: The value has been destroyed and the memory must be initialized before being used again.

Declaration

func destroy()
func destroy(_:)

Destroy the count objects the pointer points to. Precondition: The memory is initialized.

Postcondition: The value has been destroyed and the memory must be initialized before being used again.

Declaration

func destroy(count: Int)
func distanceTo(_:)

Declaration

func distanceTo(x: UnsafeMutablePointer<Memory>) -> Int

Declared In

UnsafeMutablePointer, RandomAccessIndexType, BidirectionalIndexType, ForwardIndexType
func initialize(_:)

Initialize the value the pointer points to, to construct an object where there was no object previously stored.

Precondition: The memory is not initialized.

Postcondition: The memory is initalized; the value should eventually be destroyed or moved from to avoid leaks.

Declaration

func initialize(newvalue: Memory)
func initializeFrom(_:)

Copy the elements of C into raw memory.

Precondition: The memory is not initialized.

Declaration

func initializeFrom<C : CollectionType where C.Generator.Element == Memory>(source: C)
func initializeFrom(_:count:)

Copy count values beginning at source into raw memory.

Precondition: The memory is not initialized.

Requires: self and source may not overlap.

Declaration

func initializeFrom(source: UnsafeMutablePointer<Memory>, count: Int)
func move()

Retrieve the value the pointer points to, moving it away from the location referenced in memory.

Equivalent to reading memory property and calling destroy(), but more efficient.

Precondition: The memory is initialized.

Postcondition: The value has been destroyed and the memory must be initialized before being used again.

Declaration

func move() -> Memory
func moveAssignFrom(_:count:)

Assign from count values beginning at source into initialized memory, transforming the source values into raw memory.

Requires: The self and source ranges may not overlap.

Declaration

func moveAssignFrom(source: UnsafeMutablePointer<Memory>, count: Int)
func moveInitializeBackwardFrom(_:count:)

Move count values beginning at source into uninitialized memory, transforming the source values into raw memory, proceeding from the last value to the first. Use this for copying ranges into later memory that may overlap with the source range.

Requires: Either source precedes self or follows self + count.

Declaration

func moveInitializeBackwardFrom(source: UnsafeMutablePointer<Memory>, count: Int)
func moveInitializeFrom(_:count:)

Move count values beginning at source into raw memory, transforming the source values into raw memory.

Declaration

func moveInitializeFrom(source: UnsafeMutablePointer<Memory>, count: Int)
func predecessor()

Returns the previous consecutive value before self.

Requires: The previous value is representable.

Declaration

func predecessor() -> UnsafeMutablePointer<Memory>
func stride(through:by:)

Return the sequence of values (start, start + stride, start + stride + stride, ... last) where last is the last value in the progression less than or equal to end.

Note: There is no guarantee that end is an element of the sequence.

Declaration

func stride(through end: UnsafeMutablePointer<Memory>, by stride: UnsafeMutablePointer<Memory>.Stride) -> StrideThrough<UnsafeMutablePointer<Memory>>

Declared In

RandomAccessIndexType, Strideable
func stride(to:by:)

Return the sequence of values (self, self + stride, self + stride + stride, ... last) where last is the last value in the progression that is less than end.

Declaration

func stride(to end: UnsafeMutablePointer<Memory>, by stride: UnsafeMutablePointer<Memory>.Stride) -> StrideTo<UnsafeMutablePointer<Memory>>

Declared In

RandomAccessIndexType, Strideable
func successor()

Returns the next consecutive value after self.

Requires: The next value is representable.

Declaration

func successor() -> UnsafeMutablePointer<Memory>