TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: CAMERON CLARK
from: JERRY COFFIN
date: 1997-05-22 11:04:00
subject: compiler opt.

On (18 May 97) Cameron Clark wrote to Carey Bloodworth...
 CC>     Also one of the ideas behind bootstrapping (also used to describe
 CC> a way linking the boot sequence of a machine to some other medium that
 CC> a boot drive [cdrom,network,etc]). The idea is a starting point (the
 CC> boot) and linking (strapping) to some other entity.
You're trying to take "bootstrap" too literally.  It actually originated
from the phrase "pulling himself up by his bootstraps"...
[ ... ]
 CC>     Or if you should use your own version of disk caching or if the
 CC> operating system uses its own. Example
 CC>         while not eof(file)
 CC>            read a character
 CC>     Reading a single character at a time is terribly slow method of
 CC> retreiving data but it might be lightning fast if the OS reads a
 CC> block of data at a time.
I've yet to see anything that was even roughly similar to C or C++ that
didn't have the OS read a block at a time, and simply retrieve a
character from a buffer most of the time.  OTOH, this is an area where C
and C++ are different as well.  In most C standard libraries, getchar
will be a macro that's expanded inline, so the majority of the time,
reading a character takes around a half dozen instructions or so.  If
you do processing in a reasonably tight loop, this will typically all be
in cache, and will reference memory only once, to read the character
itself.
For better or worse, iostreams are defined so that you're using a
virtual function to read a character, which means dereferencing the
`this' pointer to get a vtable pointer, then dereferencing the vtable
pointer to get a pointer to the actual function.  Then you call the
function itself, which in turn actually gets the character from the
buffer.
This adds considerable overhead and uses enough more data that it's far
less likely that everything will be in cache.  Empirical testing
indicates that it's often two to three times slower than using C style
I/O to do the same job.
Fortunately, it's possible to combine the two to some degree.  I
typically continue to use overloads of > to do my I/O, but
implement them using C style I/O functions.  This generally lowers the
overhead to a level I consider acceptable (often none at all.)
    Later,
    Jerry.
... The Universe is a figment of its own imagination.
--- PPoint 1.90
---------------
* Origin: Point Pointedly Pointless (1:128/166.5)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.