Some "safe" languages like Swift and Go offer "unsafe" pointers for use with APIs written in languages like C and Objective-C. Questions using this tag should also have the relevant language tag, e.g. [swift] or [go].
Questions tagged [unsafe-pointers]
250 questions
8
votes
1 answer
Pointers in Swift
I'm trying to understand the use of pointers in Swift, in particular: Unsafe[Mutable]Pointer and UnsafeRaw[Mutable]Pointer. I have several questions on the subject.
Is UnsafePointer equal to const T * Pointer in ? and UnsafeMutablePointer …

emacos
- 541
- 1
- 8
- 17
8
votes
2 answers
UnsafePointer from CGAffineTransform
I'm trying to create a CGPath in Swift. I'm using CGPathCreateWithRect(rect, transformPointer).
How can I get an UnsafePointer from a CGAffineTransform? I've tried this:
let transform : CGAffineTransform =…

Moshe
- 57,511
- 78
- 272
- 425
8
votes
1 answer
Getting value from unSafeMutablePointer Int16 in Swift for audio data purposes
I'm working to convert to Swift this code which helps get me get audio data for visualizations. The code I'm working with in Obj C, which works well, is:
while (reader.status == AVAssetReaderStatusReading) {
AVAssetReaderTrackOutput…

MScottWaller
- 3,321
- 2
- 24
- 47
7
votes
3 answers
Swift convert Data to UnsafeMutablePointer
I'm calling a function in an objective c class from swift.
-(char *)decrypt:(char *)crypt el:(int)el{}
when calling this function from swift, it asks for an UnsafeMutablePointer as the value for the parameter 'crypt'
the value for the…

udi
- 303
- 1
- 6
- 19
6
votes
1 answer
Why are Swift's UnsafePointer and UnsafeBufferPointer not interchangeable?
I've been working quite a bit with Apple's neural net tools, which means I've been working quite a bit with unsafe pointers. I grew up with C, and I've been working with Swift for quite a while, so I'm comfortable using them, but there's one thing…

SaganRitual
- 3,143
- 2
- 24
- 40
6
votes
2 answers
Improve performance of Bitconverter.ToInt16
I am collecting data from a USB device and this data has to go to an audio output component. At the moment I am not delivering the data fast enough to avoid clicks in the output signal. So every millisecond counts.
At the moment I am collecting the…

Tom
- 527
- 1
- 8
- 28
6
votes
1 answer
Convert UnsafeMutablePointer to UnsafePointer
I'm using a C library in my Swift project, and one of functions requires a UnsafePointer?>! as an in-out argument where I should pass my data. But the problem is that I have this data in…

Eugene Alexeev
- 1,152
- 12
- 32
6
votes
1 answer
Understanding GCHandle.Alloc pinning in C#
I inadvertently discovered something that doesn't make sense to me. My questions are in the code comments and below:
[SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
[StructLayout(LayoutKind.Sequential, Size = 4096)]
public unsafe…

IamIC
- 17,747
- 20
- 91
- 154
6
votes
1 answer
How to convert array to UnsafeMutablePointer Swift 3.0?
Here was my workable code in the previous version of Swift:
let imageOptionsDictKeys = [ kCVPixelBufferPixelFormatTypeKey, kCVPixelBufferWidthKey, kCVPixelBufferHeightKey, kCVPixelBufferOpenGLESCompatibilityKey,…

JULIIncognito
- 1,875
- 2
- 15
- 15
6
votes
2 answers
UnsafeMutablePointer in Swift 3
I'm attempting to call SecItemCopyMatching in my keychain utility class in order to get data out of the keychain, yet I'm running into a problem with getting the result argument, UnsafeMutablePointer.
The original statement (in Swift 2,…

Jojodmo
- 23,357
- 13
- 65
- 107
6
votes
3 answers
Working with UnsafeMutablePointer array
I'm trying to work with Brad Larson's splendid GPUImage framework, and I'm struggling to process the cornerArray returned by the GPUImageHarrisCornerDetectionFilter.
The corners are returned as an array of GLFloat in an UnsafeMutablePointer - and I…

Russell
- 5,436
- 2
- 19
- 27
6
votes
1 answer
Convert **T to *unsafe.Pointer in Go
How do I convert a variable of type **T to *unsafe.Pointer?
The example below will give the compilation error:
cannot convert &ptr (type **s) to type *unsafe.Pointer
package main
import (
"sync/atomic"
"unsafe"
)
type s struct {
…

ANisus
- 74,460
- 29
- 162
- 158
5
votes
1 answer
How to convert Data to UnsafePointer?
In Swift I want to pass a data buffer (named data) of type Data to a C function (named do_something) that takes a pointer of type UnsafePointer.
Is the code example below correct? And if so, in this case is it OK to use…

ma11hew28
- 121,420
- 116
- 450
- 651
5
votes
2 answers
Unsafe Pointer iteration and Bitmap - why is UInt64 faster?
I have been doing some unsafe bitmap operations and have found out that increasing the pointer less times can lead to some big performance improvements. I am not sure why is that so, even though you do lot more bitwise operations in the loop, it…

Marino Šimić
- 7,318
- 1
- 31
- 61
5
votes
2 answers
'withUnsafeBytes' is deprecated warning when passing void* argument to c function in swift 5
I have a library parsing FIT file in swift using an externally provided c library. The parsing function takes as argument a void * data.
To call the function, I was converting the data using data.withUnsafeBytes( { (ptr: UnsafePointer) in…

Brice
- 75
- 2
- 7