Skip to content

Ptr Word8 instead of MutableByteArray in IOOp? #43

@ozkutuk

Description

@ozkutuk

First of all, thanks for this nice little library! I am experimenting with doing batch file writes, but I found the shape of IOOpWrite quite inconvenient for the usual things I might want to write (e.g. ByteString), the use of MutableByteArray being the main issue. Looking at the source code, the MutableByteArray is immediately fed to mutableByteArrayContents to access the Ptr Word8 underneath. Therefore, my question is: would it be possible for IOOp (specifically IOOpWrite, but it should probably be fine for IOOpRead too) to take Ptr Word8 directly? That way, it would be possible to, say, write ByteStrings by extracting the ForeignPtr Word8, and in turn the Ptr Word8 within, and creating an IOOp out of that.

I have actually applied this change locally and it seems to be working fine. One thing worth mentioning is that it is not possible to use isMutableByteArrayPinned to guard against unpinned buffers since we would have a plain Ptr Word8. I don't know if there is a way to infer "pinnedness" from a Ptr, but I would guess not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions