Alaric Snell-Pym scripsit: > > Character encoding/decoding needs to be done in big buffers for the > > same reason that actual I/O does. > > Why? Just because of the procedure call overhead of read-char?
Well, yes -- in a compiler. But in an interpreter, you are crossing an expensive abstraction barrier between interpreted code and compiled code every time you convert a character, which (in file-oriented programs) is probably your inner loop. Much better to have that inner loop in C, possibly inside libiconv, which knows more about the subject than the average Scheme implementer. Similarly, why not just read one byte from the filesystem whenever we want binary data? The kernel does plenty of hidden buffering already; why bother with stdio and user buffers? Because it is expensive to cross the abstraction barrier between userland and the kernel, and your performance goes to hell. > I'd have thought there's an obvious optimisation to provide procedures > to read a count of characters, or read until you hit a specified > delimiter character, and produce a string in one go; but that's just > removing the procedure call overhead of read-char. That does move up the abstraction barrier, which is good, at the expense of making character-by-character reading awkward and slow; it's the tradeoff Perl uses for lines vs. characters (line I/O is efficient, character I/O is horribly not). > Yeah, I just like to keep my options open in standards, and testing > how they'd react with outlandish cases is often illuminating! It's good to have an open mind, but not so open that your brains fall out. :-) -- John Cowan [email protected] http://ccil.org/~cowan And now here I was, in a country where a right to say how the country should be governed was restricted to six persons in each thousand of its population. For the nine hundred and ninety-four to express dissatisfaction with the regnant system and propose to change it, would have made the whole six shudder as one man, it would have been so disloyal, so dishonorable, such putrid black treason. --Mark Twain's Connecticut Yankee _______________________________________________ r6rs-discuss mailing list [email protected] http://lists.r6rs.org/cgi-bin/mailman/listinfo/r6rs-discuss
