haskellvectormemory-safety

Any memory safety concerns when using Haskell's vector unsafeFreeze / unsafeThaw on unpinned vector?


Apart from the known safety concerns documented for unsafeFreeze / unsafeThaw, is there any issue using these functions with non-pinned backing data (that is, as I understand everything except Vector.Storable)?

For example, could it happen that the GC moves the immutable vector's backing data and its unsafeThaw-ed mutable counterpart not reflecting this change, and so resulting in a stale read or mis-write?

The documentation doesn't say anything about this matter, also I assume it would break lots of code and people would be vocal if there were safety concerns, but would like to know explicitly.

Under the hood they seem to use unsafeFreezeArray and unsafeThawArray, which again don't mention any such problem, so likely all fine.


Solution

  • The short answer then is: no, the backing memory being pinned or unpinned doesn't matter for unsafeFreeze or unsafeThaw usage patterns.