[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Linux games programming tutorial-part2



Christian Reiniger wrote:

> > -1:Initialise the library
> 
> s/Initialise/Initialize/
> 
> Just some spelling errors that appear several times.
> 
> > -5:Eventually call a fonction that will quit properly the library
> 
> s/fonction/function/

French, eh? I know the feeling... (I am French Canadian)

> > /* Initialise */
> >   if (vga_init()!=0) {printf("Error initialising svgalib!\n");_exit(1);}
> 
> IIRC exit () (without the leading underscore) is the standard C function
> for abnormal exit.

_exit() is only to be used if you want a "rough" exit, like when you
have a vga_setmode(TEXT) in an atexit() handler and that you want to end
a fork()ed subprocess without switching video mode...

> >       fread(&buf,1,1,file);      /* Get one byte */
> 
> You should add a comment here that fread()ing single bytes can be quite
> slow. For demonstration purposes itīs ok, but for real-world code
> reading larger chunks at once (e.g. 8k-blocks) is better.

The "Right Way" to do this is actually to fstat() the file and look at
the st_blksize member of the struct stat returned. But I am lazy and I
use getpagesize() instead. :-) I comfort myself thinking that while
maybe I'm not optimal at the file system level, I should be optimal at
the memory access level (duh, like that would improve stuff!).

-- 
Pierre Phaneuf
Ludus Design, http://ludusdesign.com/
"First they ignore you. Then they laugh at you.
Then they fight you. Then you win." -- Gandhi