
On 16/12/09 03:02, Duncan Coutts wrote:
On Tue, 2009-12-15 at 12:48 -0800, Bryan O'Sullivan wrote:
Yes, that would amount to double-buffering, and would work nicely, only the current buffers go through foreign pointers while text uses an unpinned array. I can see why this is (so iconv can actually work), but it does introduce a fly into the ointment :-)
It should not be strictly necessary to use a ForeignPtr in this case. If the IO buffers use pinned ByteArray#s then they can still be passed to iconv for it to write into.
It should also be possible for Text to be constructed from a pinned ByteArray#.
I don't think there's any real difficulty here. The IO buffers are ForeignPtrs because we want the flexibility of being able to use mmap'd memory - the mmap-backed Handle implementation uses that. But in normal operation these ForeignPtrs have pinned ByteArray#s inside. We could provide a function of type ForeignPtr -> IO (Maybe ByteArray), and the text package can turn that into a chunk of Text. It would even be able to support reading Text from mmaped memory, because only the byte buffer needs to be mmaped, not the Char buffer. Cheers, Simon