Pointer
This compiles seamlessly to an internal pointer type. You can use this for interaction with C APIs and other ABIs or you can alternatively use the memory allocation initializers and manage your own sections of memory.
Initializers
Methods
public func free() -> Void
Frees the currently allocated segment of memory. Pointer is useless after calling this. This is not automatically called so it is recommended to place this in your class's deinit section.
public func copy(from: Pointer<Type>, count: UInt64) -> Void
Copies memory from source to current pointer with the width of the current pointer. Count specifies how many instances of
Pointer<Type>
to copy.public func copy(to: Pointer<Type>, count: UInt64) -> Void
Copies memory from current pointer to another pointer with the width of the current pointer. Count specifies how many instances of
Pointer<Type>
to copy.public func copy(from: ByteSequence, length: UInt64) -> Void
Copies from a byte sequence with a given length
public func copy(to: ByteSequence, length: UInt64) -> Void
Copies the given amount of bytes from the current pointer to the provided
ByteSequence
.public func move(from: Pointer<Type>, count: UInt64) -> Void
Moves memory from source to current pointer with the width of the current pointer. Count specifies how many instances of
Pointer<Type>
to move.The difference between this and the copy functions is that this works with overlapping memory regions.
public func move(to: Pointer<Type>, count: UInt64) -> Void
Moves memory from current pointer to another pointer with the width of the current pointer. Count specifies how many instances of
Pointer<Type>
to move.The difference between this and the copy functions is that this works with overlapping memory regions.
public func move(from: ByteSequence, length: UInt64) -> Void
Moves from a byte sequence with a given length
The difference between this and the copy functions is that this works with overlapping memory regions.
public func move(to: ByteSequence, length: UInt64) -> Void
Moves to a byte sequence with a given length
The difference between this and the copy functions is that this works with overlapping memory regions.
public func dereference() -> Type
Dereferences the value the pointer points at
public func store(value: Type) -> Void
Stores a new value where the pointer points at.
public func offset(by: Int64) -> Pointer<Type>
Offsets a pointer by an amount. This is a signed integer so pass a negative number to advance in reverse. This offset in increments of [Type]. To go by bytes you would cast the pointer to Pointer
. public func offset(by: Int32) -> Pointer<Type>
Offsets a pointer by an amount. This is a signed integer so pass a negative number to advance in reverse. This offset in increments of [Type]. To go by bytes you would cast the pointer to Pointer
. public func isNullPtr() -> Bool
Returns if the current pointer is a null pointer.
public func realloc(count: UInt64) -> Pointer<Type>
Reallocated the current array and provides a new pointer. This will automatically free the old pointer.
Static Methods
public static func +(lhs: Pointer<Type>, rhs: Int64) -> Pointer<Type>
See Pointer#offset(by:).
public static func +(lhs: Pointer<Type>, rhs: UInt64) -> Pointer<Type>
See Pointer#offset(by:).
public static func +(lhs: Pointer<Type>, rhs: Int32) -> Pointer<Type>
See Pointer#offset(by:).
public static func +(lhs: Pointer<Type>, rhs: UInt32) -> Pointer<Type>
See Pointer#offset(by:).
public static func -(lhs: Pointer<Type>, rhs: UInt64) -> Pointer<Type>
See Pointer#offset(by:).
public static func -(lhs: Pointer<Type>, rhs: UInt32) -> Pointer<Type>
See Pointer#offset(by:).
public static func sizeof() -> UInt64
Returns sizeof what this points to. Do note that classes are actually pointers to their internal data buffer so calling this on a pointer to a class will actually return the size of the pointer. To obtain the sizeof a pointer's true content use either the Reflection#heapSize() to obtain the size of an object's representation in the heap or use the Pointer#underlyingSizeof() which does roughly the same.
public static func underlyingSizeof() -> UInt64
Returns the 'underlying' sizeof of a provided type. What this means if the underlying type itself is a pointer to the actual item that contains the data, this will return the sizeof that. An example is if there is a class 'Animal', Pointer
.underlyingSizeof() will return the sizeof the data struct for 'animal' not the sizeof an Animal*. public static func alloc(count: UInt64) -> Pointer<Type>
Alocates a count instances of a passed type.