# Reading and decompressing a bunch of floats from a FileDescriptor, minimizing copies

**URL:** <https://forums.swift.org/t/reading-and-decompressing-a-bunch-of-floats-from-a-filedescriptor-minimizing-copies/73413>\
**Category:** Using Swift\
**Created:** [July 24, 2024, 10:06am UTC](https://forums.swift.org/t/reading-and-decompressing-a-bunch-of-floats-from-a-filedescriptor-minimizing-copies/73413 "2024-07-24T10:06:46Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![Karl](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@Karl](https://forums.swift.org/u/Karl)\
**Post date:** [July 30, 2024, 2:10pm UTC](https://forums.swift.org/t/reading-and-decompressing-a-bunch-of-floats-from-a-filedescriptor-minimizing-copies/73413/8 "2024-07-30T14:10:24Z")

</div>

> [@JetForMe](#):
>
> In C, I'd just do this:
> 
> ```swift
> float* data = (float*) decompressedData;
> 
> ```
> 
> Surely there’s an equivalent in Swift, I just can't figure out the right incantation of `Unsafe[Mutable][Raw][Buffer][Pointer]` to do it. Honestly, I _hate_ this aspect of Swift, or at least the documentation around it. Each one is documented in isolation, and there’s no overarching document with nice images and tables to show how each `Unsafe*` thing relates to the other, and how to do all the typical things the API enables. The lack of example code is a significant weakness of all of Apple's documentation.

There are WWDC talks which explain how to use them, but yes, overall the documentation is kind of weak. I think the reason that is the case is because we're reluctant to present the unsafe APIs as a solution for this kind of problem. It's very much an experts-only tool and we don't want to advertise it like everybody should immediately reach for `UnsafeBufferPointer`.

Long-term, `Span<T>` and `RawSpan` ([pitch](https://forums.swift.org/t/pitch-2-safe-access-to-contiguous-storage/72745)) are designed to support these kinds of things in a safe, convenient way. I expect there will probably be a greater investment in documenting how to use them for processing binary data.

---

_[View the full topic](https://forums.swift.org/t/reading-and-decompressing-a-bunch-of-floats-from-a-filedescriptor-minimizing-copies/73413)._
