Binary IO

Glynn Clements glynn at gclements.plus.com
Fri Apr 22 16:31:41 EDT 2005


Peter Simons wrote:

>  > Does anyone have any *objections* to introducing
> 
>  >   System.IO.hGetWord8 :: Handle -> IO Word8
>  >   System.IO.hPutWord8 :: Word8 -> Handle -> IO Word8
> 
> I don't mind having these functions, but to be honest I
> doubt that they would be useful for real life applications.
> Reading a byte at a time is a performance nightmare,
> buffering or not.

That depends upon the language overhead. E.g. C's getc() may be a
macro which is essentially

	fp->read_ptr < fp->read_end
	 ? fp->buf[fp->read_ptr++]
	 : ...

where the ... case is only called once per block.

Obviously, block interfaces make the per-call overhead less
significant, but they also make the code more complex.

In any case, we already have h{Get,Put}Char, and people seem to be
willing to tolerate the inefficiency there.

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the Libraries mailing list