composewell/streamly

Add array conversion to and from foreignptr

Closed this issue · 2 comments

Introduce something like toForeignPtr and fromForeignPtr so that we can implement the toArray and fromArray in streamly-bytestring.

toForeignPtr does not make sense when bounds aren't involved. We pass in the
whole MutableByteArray# to the ForeignPtr which has the information of
arrayCapacity but not arrayLength.
(ForeignPtr, Int) will have all the information of Array without loss.
We can however introduce asForeignPtr passing the length as well.

We have introduced unsafeAsForeignPtr