I am linking Haskell to an image loading library and I want to avoid copying as much as possible. When the image loads, I return the data structure from the C library containing the image data. Now this structure is unchanged for all purposes and tasks, but reading data from it in Haskell is an IO action. Would it be nice to use unsafePerformIO (or perhaps unsafeDupablePerformIO to improve performance) to avoid copying memory into a Haskell array or the like? Of course, I would need to encapsulate the data structure pointer in ForeignPtr or similar and ensure that the pointer cannot be accessed or changed in any other way.
What is agreement in such cases?
, PierformIO FFI . unsafePerformIO , , . - , , opprotunity , , , , -, , , . . , , , , . , .
, , , , haskell ForeginPtr, , , , , IO- . guarentees, - .