The Daily Static
  The Daily Static
UF Archives
Register
UF Membership
Ad Free Site
Postcards
Community

Geekfinder
UFie Gear
Advertise on UF

Forum Rules
& FAQ


Username

Password


Create a New Account

 
 

Back to UserFriendly Strip Comments Index

Some programming help by eof2005-01-27 05:30:17
  Some answers by Hessofanes 2005-01-27 07:02:09
#1: Yes, reading blockwise into a buffer will be _many times_ faster than reading the bytes one by one.

#2,3: I think the best buffer size depends on the blocksize of the underlying filesystem - you should get the best performance if you read in chunks of the same size. IIRC this blocksize usually is 4 or 8K, but I could be wrong there.

#4: Hm no, if you're not allowed to view the file's metadata (size) directly, then you have to really _read_ the data, and that means it gets written in a buffer. There's no read&discard I know of.

#5: Yes, you could use fgets, but that might become awfully slow, too... fgets stops reading at the next newline or at EOF, so if you happen to read a file full of ASCII 0x0a's (newlines), then you'll again be reading bytes one by one. I'd suggest the (non-portable) read call - which also has another advantage, in that it doesn't return a pointer to the buffer, but the number of bytes read, so you don't have to call strlen().
[ Reply ]
    Thanks... by eof2005-01-27 08:00:33
      Which one? by Hessofanes2005-01-27 11:44:11
        read.... by eof2005-01-27 22:15:56

 

[Todays Cartoon Discussion] [News Index]

Come get yer ARS (Account Registration System) Source Code here!
All images, characters, content and text are copyrighted and trademarks of J.D. Frazer except where other ownership applies. Don't do bad things, we have lawyers.
UserFriendly.Org and its operators are not liable for comments or content posted by its visitors, and will cheerfully assist the lawful authorities in hunting down script-kiddies, spammers and other net scum. And if you're really bad, we'll call your mom. (We're not kidding, we've done it before.)