stéphane69 wrote:
Again, please talk about what you understand and know.
Learn programming.
return value of fread is not unsigned short (your example above) or int and there is reason for that.
reasons that obviously you do not know.
Again learn programming.
And if you want to continue barking like you do on this problem its your choice, its just wasting time and trolling.
At this point, it is mostly morbid fascination 🙂
I'm curious why you keep saying "unsigned short". Is that because I used a buffer size of 65536? It has nothing to do with unsigned short. That is just an optimal buffer size. Once you get any larger than that, the return on speed from larger sizes drops very quickly. Furthermore, in a modern application, your process will lock up if you try a buffer size of 1 GB. If you read in smaller chunks, you can keep processing events and updating progress bars.
For example, I took my demo program and changed the buffer size. I used it to copy a 1.6 GB file. Here are the results:
64K buffer
$ time /tmp/a.out "in.dmg" out.bin
/tmp/a.out "in.dmg" out.bin 0.19s user 5.18s system 6% cpu 1:17.31 total
128K buffer
$ time /tmp/a.out "in.dmg" out.bin2
/tmp/a.out "in.dmg" out.bin2 0.18s user 5.19s system 18% cpu 28.864 total
256K buffer
$ time /tmp/a.out "in.dmg" out.bin3
/tmp/a.out "in.dmg" out.bin3 0.17s user 5.14s system 17% cpu 30.090 total
1 GB buffer
$ time /tmp/a.out "in.dmg" out.bin4
/tmp/a.out "in.dmg" out.bin4 0.16s user 5.64s system 18% cpu 31.113 total
In this example, 128K is actually what I should have used. Using a buffer any larger than that actually makes the program run more slowly.
Look, I realize you are a new programmer so I'm trying to help here. Having a belligerant attitude like that will be a Career Limiting Move. I make a point not to explain in Apple Support Communities the kind of software I write professionally. I prefer to engage people and explain things in a way that they can understand instead of making claims of X, Y, and Z that could never be substantiated anyway.
I would like to help you become a better programmer if you will meet me halfway. If not, then that's your loss.