Coercing a `ByteArray#` into a `MutableByteArray#`
Ben Gamari
ben at smart-cactus.org
Mon Jul 24 19:21:45 UTC 2023
Adithya Kumar <adi.obilisetty at gmail.com> writes:
> Hello all,
>
> I have a use-case where I want to convert `ByteArray#` to
> `MutableByteArray#`
> without the copy overhead.
>
> Is the underlying memory structure of `ByteArray#` and `MutableByteArray#`
> the same?
>
> If I can guarantee that I won't mutate my `MutableByteArray#`, can I use
> `unsafeCoerce#` on `ByteArray#` and treat it as `MutableByteArray#`?
>
Note that a future release of GHC (IIRC 9.10) will have a (no-op)
operation for precisely this purpose. See [1].
Cheers,
- Ben
[1] https://gitlab.haskell.org/ghc/ghc/-/issues/22710
More information about the ghc-devs
mailing list