composewell / streamly

High performance, concurrent functional programming abstractions
https://streamly.composewell.com
Other
861 stars 66 forks source link

asPtrUnsafe should return the new array #2650

Open harendra-kumar opened 9 months ago

harendra-kumar commented 9 months ago

It reallocates the memory of the array and we could continue using the old array.

asPtrUnsafe :: MonadIO m => MutByteArray -> (Ptr a -> m b) -> m b
asPtrUnsafe arr f = do
  contents <- liftIO $ pin arr
  let !ptr = Ptr (byteArrayContents#
                     (unsafeCoerce# (getMutableByteArray# contents)))
  r <- f ptr
  liftIO $ touch contents
  return r