# \#pointers

**URL:** https://forums.swift.org/tag/pointers/333.md

[Latest](https://forums.swift.org/latest.md) · [Categories](https://forums.swift.org/categories.md) · [Tags](https://forums.swift.org/tags.md)

---

## [Passing String and Data sequences to sqlite\_carray\_bind](https://forums.swift.org/t/passing-string-and-data-sequences-to-sqlite-carray-bind/89832)

<div class="topic-metadata">

**Author:** [@prathameshk](https://forums.swift.org/u/prathameshk)\
**Replies:** 3\
**Last updated:** [October 3, 2026, 8:51am UTC](https://forums.swift.org/t/passing-string-and-data-sequences-to-sqlite-carray-bind/89832 "2026-10-03T08:51:34Z")

</div>

I'm trying to work with sqlite\_carray\_bind from the sqlite library. Here is what I have working for binding a sequence of strings: func bind\<S: Sequence\<String\>\>(strings: S, to statement: OpaquePointer?, at index: Int3…

---

## [Data.withUnsafeBytes and type annotations](https://forums.swift.org/t/data-withunsafebytes-and-type-annotations/89585)

<div class="topic-metadata">

**Author:** [@jdf-id-au](https://forums.swift.org/u/jdf-id-au)\
**Replies:** 4\
**Last updated:** [September 16, 2026, 4:41am UTC](https://forums.swift.org/t/data-withunsafebytes-and-type-annotations/89585 "2026-09-16T04:41:33Z")

</div>

Hi everyone, I'm searching through multi-gigabyte files for newlines, starting with let raw = try Data(contentsOf: url, options: .alwaysMapped) The following implementation compiles and works, but seems slow. raw.wit…

---

## [\[Discussion\] Bag of Bytes Types](https://forums.swift.org/t/discussion-bag-of-bytes-types/86983)

<div class="topic-metadata">

**Author:** [@jmschonfeld](https://forums.swift.org/u/jmschonfeld)\
**Replies:** 33\
**Last updated:** [July 3, 2026, 11:21am UTC](https://forums.swift.org/t/discussion-bag-of-bytes-types/86983 "2026-07-03T11:21:49Z")

</div>

Hi everyone, For Swift 6.4, I’ve spent a fair amount of time working on bag of bytes types (including Data in particular). Based on community feedback and some performance investigations, Data has now gained some fairly…

---

## [Is ~Escapable + ~Copyable sufficient to safely scope an UnsafeMutablePointer lifetime?](https://forums.swift.org/t/is-escapable-copyable-sufficient-to-safely-scope-an-unsafemutablepointer-lifetime/86153)

<div class="topic-metadata">

**Author:** [@Blacksmith](https://forums.swift.org/u/Blacksmith)\
**Replies:** 0\
**Last updated:** [April 21, 2026, 5:11pm UTC](https://forums.swift.org/t/is-escapable-copyable-sufficient-to-safely-scope-an-unsafemutablepointer-lifetime/86153 "2026-04-21T17:11:40Z")

</div>

Hello everyone, I've been experimenting with some of the newer Swift proposals and wanted to check whether my mental model aligns with the reality. I have a type called Context that is generic over some State. It is bo…

---

## [Is it safe to keep a span alive and use its pointer across a suspension?](https://forums.swift.org/t/is-it-safe-to-keep-a-span-alive-and-use-its-pointer-across-a-suspension/85382)

<div class="topic-metadata">

**Author:** [@orobio](https://forums.swift.org/u/orobio)\
**Replies:** 4\
**Last updated:** [March 18, 2026, 11:25am UTC](https://forums.swift.org/t/is-it-safe-to-keep-a-span-alive-and-use-its-pointer-across-a-suspension/85382 "2026-03-18T11:25:09Z")

</div>

What I'm doing is the following: func write(\_ span: Span\<UInt8\>) async { let spanBufferPointer = span.withUnsafeBytes { $0 } // Get the pointer. Usually a bad pattern. defer { extendLifetime(span) } // Pointer m…

---

## [Presumably unsafe \`withUnsafeMutablePointer\` usage pattern](https://forums.swift.org/t/presumably-unsafe-withunsafemutablepointer-usage-pattern/84298)

<div class="topic-metadata">

**Author:** [@tera](https://forums.swift.org/u/tera)\
**Replies:** 1\
**Last updated:** [January 22, 2026, 2:16pm UTC](https://forums.swift.org/t/presumably-unsafe-withunsafemutablepointer-usage-pattern/84298 "2026-01-22T14:16:50Z")

</div>

Consider this fragment: import Foundation struct Foo { var a: Int64 = 1 var b: Int64 = 2 mutating func secondValuePointer() -\> UnsafeMutablePointer\<Int\> { return withUnsafeMutablePointer(to: &s…

---

## [How a ptrauth blend constant is calculated for Swift methods?](https://forums.swift.org/t/how-a-ptrauth-blend-constant-is-calculated-for-swift-methods/83414)

<div class="topic-metadata">

**Author:** [@gitevedev](https://forums.swift.org/u/gitevedev)\
**Replies:** 2\
**Last updated:** [November 27, 2025, 11:06am UTC](https://forums.swift.org/t/how-a-ptrauth-blend-constant-is-calculated-for-swift-methods/83414 "2025-11-27T11:06:39Z")

</div>

Hello, I am researching how arm64e pointer authentication signing is implemented in Swift metadata, and I’ve noticed that for Swift methods, the metadata pointers are signed with a blend constant (the last argument of t…

---

## [How to think properly about binding memory](https://forums.swift.org/t/how-to-think-properly-about-binding-memory/81841)

<div class="topic-metadata">

**Author:** [@jeremyabannister](https://forums.swift.org/u/jeremyabannister)\
**Replies:** 4\
**Last updated:** [September 4, 2025, 12:24pm UTC](https://forums.swift.org/t/how-to-think-properly-about-binding-memory/81841 "2025-09-04T12:24:20Z")

</div>

I’m trying to use the compression\_stream type from the Compression framework, and I have some questions about the concept of binding raw memory to a type. compression\_stream requires that I set its src\_ptr property, whic…

---

## [Is it safe to deinitialize() uninitialized memory if it was bound to a trivial type?](https://forums.swift.org/t/is-it-safe-to-deinitialize-uninitialized-memory-if-it-was-bound-to-a-trivial-type/81869)

<div class="topic-metadata">

**Author:** [@jeremyabannister](https://forums.swift.org/u/jeremyabannister)\
**Replies:** 5\
**Last updated:** [August 29, 2025, 5:33pm UTC](https://forums.swift.org/t/is-it-safe-to-deinitialize-uninitialized-memory-if-it-was-bound-to-a-trivial-type/81869 "2025-08-29T17:33:59Z")

</div>

I have been reading related threads and I have seen it clearly stated in several places (for example here) that it is safe to skip the call to deinitialize() on memory if it is bound to a “trivial type”, which I understa…

---

## [Classes, stored properties, pointer conversion and address stability](https://forums.swift.org/t/classes-stored-properties-pointer-conversion-and-address-stability/76376)

<div class="topic-metadata">

**Author:** [@jamieQ](https://forums.swift.org/u/jamieQ)\
**Replies:** 5\
**Last updated:** [December 5, 2024, 2:39pm UTC](https://forums.swift.org/t/classes-stored-properties-pointer-conversion-and-address-stability/76376 "2024-12-05T14:39:55Z")

</div>

consider code such as this, which wraps an os\_unfair\_lock in a class: final class MyLock { private var lock = os\_unfair\_lock\_s() func lock() { os\_unfair\_lock\_lock(&lock) } func unlock() { o…

---

## [Determine origin of a SwiftPM Dependency](https://forums.swift.org/t/determine-origin-of-a-swiftpm-dependency/76296)

<div class="topic-metadata">

**Author:** [@nashysolutions](https://forums.swift.org/u/nashysolutions)\
**Replies:** 2\
**Last updated:** [December 2, 2024, 11:19am UTC](https://forums.swift.org/t/determine-origin-of-a-swiftpm-dependency/76296 "2024-12-02T11:19:24Z")

</div>

Hi, My Xcode project has a vast mixture of dependencies and I want to be able to quickly determine why a certain SPM package is a dependency. The following command swift package show-dependencies is useful in a single…

---

## [\[Unsafe Pointers\] Which is the expected behavior? Crash or not?](https://forums.swift.org/t/unsafe-pointers-which-is-the-expected-behavior-crash-or-not/75345)

<div class="topic-metadata">

**Author:** [@YOCKOW](https://forums.swift.org/u/YOCKOW)\
**Replies:** 6\
**Last updated:** [October 14, 2024, 11:11am UTC](https://forums.swift.org/t/unsafe-pointers-which-is-the-expected-behavior-crash-or-not/75345 "2024-10-14T11:11:04Z")

</div>

To begin with the conclusion, the following (experimental) code can be executed successfully on macOS whereas a run-time error happens on Linux. protocol MyProtocol { var string: String { get set } } struct MyStruct:…

---

## [Does UnsafePointer create a weak reference to the referenced object?](https://forums.swift.org/t/does-unsafepointer-create-a-weak-reference-to-the-referenced-object/75197)

<div class="topic-metadata">

**Author:** [@RussBaz](https://forums.swift.org/u/RussBaz)\
**Replies:** 17\
**Last updated:** [October 9, 2024, 7:16pm UTC](https://forums.swift.org/t/does-unsafepointer-create-a-weak-reference-to-the-referenced-object/75197 "2024-10-09T19:16:02Z")

</div>

Hi. Does a pointer object create a strong reference to an object for ARC to retain it, or is it a (unsafe) weak reference? I suspect it is the latter, but please confirm. Also, does UnsafeMutablePointer.initialize(to:) …

---

## [Create a nonnull UnsafeRawPointer of underlying rawValue 0](https://forums.swift.org/t/create-a-nonnull-unsaferawpointer-of-underlying-rawvalue-0/75225)

<div class="topic-metadata">

**Author:** [@Kyle-Ye](https://forums.swift.org/u/Kyle-Ye)\
**Replies:** 9\
**Last updated:** [October 8, 2024, 3:12pm UTC](https://forums.swift.org/t/create-a-nonnull-unsaferawpointer-of-underlying-rawvalue-0/75225 "2024-10-08T15:12:29Z")

</div>

Issue If we use .init(bitPattern:) and pass 0 here. We'll get a nil value. An alternative way is use unsafeBitCast(0, to: UnsafeRawPointer). Unfortunately, a warning will be emitted and I'm use werror here. 'unsafeBit…

---

## [Raw Pointer Address](https://forums.swift.org/t/raw-pointer-address/74894)

<div class="topic-metadata">

**Author:** [@RussBaz](https://forums.swift.org/u/RussBaz)\
**Replies:** 0\
**Last updated:** [September 23, 2024, 7:42pm UTC](https://forums.swift.org/t/raw-pointer-address/74894 "2024-09-23T19:42:47Z")

</div>

Hi. I have the following code: @inlinable func setStreamData(on stream: UnsafeMutablePointer\<some UVStreamRepresentable\>, to data: UnsafeMutablePointer\<some AnyObject\>) { let stream = castToBaseStream(stream) f…

---

## [Can we still not mix Swift and C in a module?](https://forums.swift.org/t/can-we-still-not-mix-swift-and-c-in-a-module/73287)

<div class="topic-metadata">

**Author:** [@JetForMe](https://forums.swift.org/u/JetForMe)\
**Replies:** 4\
**Last updated:** [July 21, 2024, 12:17am UTC](https://forums.swift.org/t/can-we-still-not-mix-swift-and-c-in-a-module/73287 "2024-07-21T00:17:50Z")

</div>

Unfortunately, the libraries I want to use (libtiff and libgeotiff) have a lot of variadic function calls like this: extern int TIFFGetField(TIFF \*tif, uint32\_t tag, ...); As I understand it, this can't be imported int…

---

## [Struct Memory Layout](https://forums.swift.org/t/struct-memory-layout/72209)

<div class="topic-metadata">

**Author:** [@nmgswift](https://forums.swift.org/u/nmgswift)\
**Replies:** 13\
**Last updated:** [June 2, 2024, 2:43pm UTC](https://forums.swift.org/t/struct-memory-layout/72209 "2024-06-02T14:43:03Z")

</div>

Hello! I'm writing a library (currently for my own personal use) that interfaces with a C-level API that takes in a pointer to a variable buffer. I wanted to include type definitions, so I built an API that binds the me…

---

## [Questions about raw and typed pointers and generic](https://forums.swift.org/t/questions-about-raw-and-typed-pointers-and-generic/69900)

<div class="topic-metadata">

**Author:** [@Luminaron](https://forums.swift.org/u/Luminaron)\
**Replies:** 5\
**Last updated:** [February 7, 2024, 1:51pm UTC](https://forums.swift.org/t/questions-about-raw-and-typed-pointers-and-generic/69900 "2024-02-07T13:51:06Z")

</div>

I wrote some functions for Swift pointers for learning and couldn’t understand the results I am getting. The code: Questions about raw and typed pointers and generic - #3 by Luminaron My experiments revolve around the …

---

## [Inconsistent treatment bewtween Swift pointer parameters and C ones](https://forums.swift.org/t/inconsistent-treatment-bewtween-swift-pointer-parameters-and-c-ones/69855)

<div class="topic-metadata">

**Author:** [@carlynorama](https://forums.swift.org/u/carlynorama)\
**Replies:** 6\
**Last updated:** [February 6, 2024, 2:41am UTC](https://forums.swift.org/t/inconsistent-treatment-bewtween-swift-pointer-parameters-and-c-ones/69855 "2024-02-06T02:41:43Z")

</div>

C functions that take pointers get treated differently than Swift functions that take pointers. C ones get treated as inout requests accross the board, where ones from Swift do not. That means Swift functions that take …

---

## [Accessing address of a C global const variable - cannot pass immutable value as inout argument](https://forums.swift.org/t/accessing-address-of-a-c-global-const-variable-cannot-pass-immutable-value-as-inout-argument/69468)

<div class="topic-metadata">

**Author:** [@oliviermartin](https://forums.swift.org/u/oliviermartin)\
**Replies:** 7\
**Last updated:** [January 16, 2024, 9:15pm UTC](https://forums.swift.org/t/accessing-address-of-a-c-global-const-variable-cannot-pass-immutable-value-as-inout-argument/69468 "2024-01-16T21:15:47Z")

</div>

Context: I want to access the address of a C global const variable in Swift. Here is my simple project: Package.swift // swift-tools-version: 5.9 // The swift-tools-version declares the minimum version of Swift requi…

---

## [Documentation question for UnsafeMutablePointer](https://forums.swift.org/t/documentation-question-for-unsafemutablepointer/67945)

<div class="topic-metadata">

**Author:** [@Kyle-Ye](https://forums.swift.org/u/Kyle-Ye)\
**Replies:** 3\
**Last updated:** [October 24, 2023, 4:52am UTC](https://forums.swift.org/t/documentation-question-for-unsafemutablepointer/67945 "2023-10-24T04:52:02Z")

</div>

Why do we declare in the document comments of the initialization method of the UnsafeMutablePointer type that it "Create an immutable typed pointer"? I am a little confused by the doc statement here. Could you help che…

---

## [\[Pitch\] Restrict pointer conversion to C interoperability](https://forums.swift.org/t/pitch-restrict-pointer-conversion-to-c-interoperability/66515)

<div class="topic-metadata">

**Author:** [@glessard](https://forums.swift.org/u/glessard)\
**Replies:** 21\
**Last updated:** [August 10, 2023, 4:26pm UTC](https://forums.swift.org/t/pitch-restrict-pointer-conversion-to-c-interoperability/66515 "2023-08-10T16:26:06Z")

</div>

I propose restricting pointer conversions in Swift to the C interop use case. Constrain Pointer Conversion Feature to C-interoperability Proposal: SE-NNNN Constrain Pointer Conversion Feature to C-interoperability Aut…

---

## [Pointers to Never](https://forums.swift.org/t/pointers-to-never/65257)

<div class="topic-metadata">

**Author:** [@bbrk24](https://forums.swift.org/u/bbrk24)\
**Replies:** 12\
**Last updated:** [May 31, 2023, 9:50am UTC](https://forums.swift.org/t/pointers-to-never/65257 "2023-05-31T09:50:00Z")

</div>

Consider some code like the following: import Foundation if let ptr = calloc(1, MemoryLayout\<Never\>.stride)?.bindMemory(to: Never.self, capacity: 1) { print("Dereferencing pointer to Never") ptr.pointee // Expressi…

---

## [Referencing memory via a variety of Arrays](https://forums.swift.org/t/referencing-memory-via-a-variety-of-arrays/64554)

<div class="topic-metadata">

**Author:** [@Gavin\_Eadie](https://forums.swift.org/u/Gavin_Eadie)\
**Replies:** 1\
**Last updated:** [April 23, 2023, 5:10am UTC](https://forums.swift.org/t/referencing-memory-via-a-variety-of-arrays/64554 "2023-04-23T05:10:27Z")

</div>

I suspect this is really easy but it is evading me. I have a file representing a disk image read into memory as type Data. I want to be able to address this image as an array of Sectors and, in turn, address Sectors as…

---

## [Why is \`UnsafeBufferPointer\`'s \`baseAddress\` optional?](https://forums.swift.org/t/why-is-unsafebufferpointer-s-baseaddress-optional/62791)

<div class="topic-metadata">

**Author:** [@CharlesS](https://forums.swift.org/u/CharlesS)\
**Replies:** 68\
**Last updated:** [March 21, 2023, 1:45am UTC](https://forums.swift.org/t/why-is-unsafebufferpointer-s-baseaddress-optional/62791 "2023-03-21T01:45:28Z")

</div>

I thought I remembered something from long ago about a nil baseAddress denoting an empty buffer with zero count, but I've recently encountered buffer pointers where the count was zero and the base address wasn't nil, and…

---

## [Same-type requirement makes generic parameters 'T' and 'Pointee' equivalent; this is an error in Swift 6 warning](https://forums.swift.org/t/same-type-requirement-makes-generic-parameters-t-and-pointee-equivalent-this-is-an-error-in-swift-6-warning/62908)

<div class="topic-metadata">

**Author:** [@DrAma999](https://forums.swift.org/u/DrAma999)\
**Replies:** 2\
**Last updated:** [February 2, 2023, 8:36am UTC](https://forums.swift.org/t/same-type-requirement-makes-generic-parameters-t-and-pointee-equivalent-this-is-an-error-in-swift-6-warning/62908 "2023-02-02T08:36:42Z")

</div>

I had this this extensions that used to work before swift 5.7, now it throws a warning. It is used to create a contiguous array from a buffer of C structs. extension UnsafeMutablePointer { func toContiguousArray\<T\>(…

---

## [How do I initialize a C struct from a Data object?](https://forums.swift.org/t/how-do-i-initialize-a-c-struct-from-a-data-object/62323)

<div class="topic-metadata">

**Author:** [@snej](https://forums.swift.org/u/snej)\
**Replies:** 6\
**Last updated:** [January 1, 2023, 5:12am UTC](https://forums.swift.org/t/how-do-i-initialize-a-c-struct-from-a-data-object/62323 "2023-01-01T05:12:45Z")

</div>

Hi, I’m an expert C/C++ coder, and mostly comfortable in Swift, but I often end up needing to bridge to C APIs, and this always gets me confused and frustrated due to all the all the different unsafe pointer and buffer t…

---

## [Dangling pointer from array](https://forums.swift.org/t/dangling-pointer-from-array/61609)

<div class="topic-metadata">

**Author:** [@luciy](https://forums.swift.org/u/luciy)\
**Replies:** 4\
**Last updated:** [November 25, 2022, 1:35pm UTC](https://forums.swift.org/t/dangling-pointer-from-array/61609 "2022-11-25T13:35:15Z")

</div>

Hello, i work with pointers in my app. And compilation of something like this gives me a warning at the second line: "Initialization of 'UnsafeBufferPointer' results in a dangling buffer pointer." And i don't get it. Th…

---

## [Help me diagnose inconsistent test failures on unsafe code](https://forums.swift.org/t/help-me-diagnose-inconsistent-test-failures-on-unsafe-code/60546)

<div class="topic-metadata">

**Author:** [@crichez](https://forums.swift.org/u/crichez)\
**Replies:** 0\
**Last updated:** [September 28, 2022, 2:25pm UTC](https://forums.swift.org/t/help-me-diagnose-inconsistent-test-failures-on-unsafe-code/60546 "2022-09-28T14:25:15Z")

</div>

I am trying to manually manage memory to implement a custom collection, and I'm running into flaky test failures. I have a LeafNode class that stores an UnsafeMutablePointer\<Int\> to store indices of another collection. …

---

## [SE-0370: Pointer family initialization improvements and better buffer slices](https://forums.swift.org/t/se-0370-pointer-family-initialization-improvements-and-better-buffer-slices/59724)

<div class="topic-metadata">

**Author:** [@John\_McCall](https://forums.swift.org/u/John_McCall)\
**Replies:** 34\
**Last updated:** [August 31, 2022, 12:15am UTC](https://forums.swift.org/t/se-0370-pointer-family-initialization-improvements-and-better-buffer-slices/59724 "2022-08-31T00:15:35Z")

</div>

Hello Swift community, The review of SE-0370: Pointer family initialization improvements and better buffer slices begins now and runs through August 29th, 2022. Reviews are an important part of the Swift evolution proc…

[Next page](https://forums.swift.org/tag/pointers/333.md?match_all_tags=true&page=1&tags%5B%5D=pointers)
