4 ms·
Stdio would add unnecessary overhead. And why bother with stdio (or its Plan 9 equivalent) when it's so easy to do the buffering faster yourself?
by p9idf 15y ago
Stdio would add unnecessary overhead. And why bother with stdio (or its Plan 9 equivalent) when it's so easy to do the buffering faster yourself?
- haberman 15y agoOverhead such as...? The only one I can think of is the mutex lock/unlock, but there are the _unlocked variants for those. "And why bother with stdio (or its Plan 9 equivalent) when it's so easy to do the buffering faster yourself?" For the same reason you'd use any abstraction: to keep your program simpler. Even if you consider it "so easy" there are plenty of opportunities there for off-by-one errors and buffer overflows that would disappear if you used stdio instead.
- p9idf 15y agoPlease point out the plentiful opportunities for off-by-one errors in Plan 9's echo.c. If you send me a copy of Plan 9's echo.c using stdio I will run it and benchmark it for you.
- bodyfour 15y agoRemember that echo.c evolved long before UNIX has shared libraries. So avoiding stdio completely might mean the size of your binary drops from 50K to 5K. If you're on a PDP-11 with 256KB of RAM (being shared by several users) this would make a big difference. My earliest UNIX programming was in the mid-80s on a machine with a (luxurious!) 1.5MB of RAM. I definitely remember avoiding stdio when writing small utilities that I wanted to start up and run fast. Also remember that back in those days echo was not a shell builtin. (Hell, back then the testing operator '[' wasn't even a builtin. Some UNIXes like OS/X still have a vestigial /bin/[ executable!) Programs like echo that ran from shell scripts constantly had to be coded to start up as fast as possible.
- EdiX 15y ago> Some UNIXes like OS/X still have a vestigial /bin/[ executable! This includes linux, but it's in /usr/bin/[
- dchest 15y agoThis was actually the reason for FreeBSD's more complicated version. Revision 106835: Put echo on a diet, removing unnecessary use of stdio and getopt. Before... -r-xr-xr-x 1 root wheel 58636 Oct 28 05:16 /bin/echo After... -rwxr-xr-x 1 root wheel 12824 Nov 12 17:39 /usr/obj/usr/src/bin/echo/echo http://svnweb.freebsd.org/base?view=revision&revision=106835 http://svnweb.freebsd.org/base?view=revision&revision=10...