Proposal: add ByteString support to unix:System.Posix.IO API

Antoine Latter aslatter at
Wed Mar 2 07:58:39 CET 2011

On Tue, Mar 1, 2011 at 9:23 PM, wren ng thornton <wren at> wrote:
> On 3/1/11 1:35 AM, Bryan O'Sullivan wrote:
>> I want to see four entry points for writing:
>> fdWrite :: Strict.ByteString ->  IO Int
>> fdWriteAll :: Strict.ByteString ->  IO ()
>> fdWritev :: [Strict.ByteString] ->  IO Int -- turn the list into an iovec,
>> then call writev
>> fdWritevAll :: [Strict.ByteString] ->  IO ()
> Using writev requires the length of the list in order to get a count of
> chunks, which forces us to hold the whole list/lazy-bytestring in memory at
> once and also adds O(n) time for traversing it. Also it'd require converting
> each of the ByteString structs into iovec structs (whereas using write
> allows this to be unpacked into the call frames for write).
> What's the benefit of doing this? Is writev that much more efficient than
> Haskell code with the same semantics[1]?

The benefit of using 'writev' over multiple calls to 'write' is the
'writev' is frequently a single kernel call - avoiding multiple
context switches.

Whether or not it is worth it to hang on to the entire bytestring to
get this advantage probably depends on the circumstance.


More information about the Libraries mailing list