Sliding window

F

filia&sofia

If Eric Sossman gave the "standard" way of doing the trick, I didn't
know it was a standard way of doing it - I wanted more possible ways
to be able to discuss them later. Generally, I'm interested in how
would you write a program that reads n-bit numbers from a file (but I
do not want anyone to write the program, I'm going to do it myself as
soon as I understand how I should do it). I know that there isn't
enough information available, but I thought that it would be a good
thing to give room for ideas. Is Eric's suggestion the only one?
 
R

Richard Tobin

CBFalconer said:
Nonsense. Just use getc and putc. They are designed to be macro
implementable (but ensure in the call that their arguments do not
need to be evaluated more than once) and thus use the built-in
stream buffers. You are very likely to find that the fastest file
copy routine is:

int filecpy(FILE *f1, FILE *f2) {
int ch;

while (EOF != (ch = getc(f1))) putc(ch, f2);
return ch;
}

If it isn't the fastest, it may be that your system fails to
provide putc/getc macros.

Unfortunately, as discussed here recently, some widely-used systems
do not make getc and putc efficient, in a (misguided) attempt to
provide thread safety. Using fread() and fwrite() is likely
to be much faster on these systems, and at least as good on others.

-- Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,053
Members
48,769
Latest member
Clifft

Latest Threads

Top