G
grunes
I wish to fread a few thousand bytes at a time in turn from several
very large files from a DVD data disk, under Redhat Fedora Linux.
When this is done the DVD drive wastes a lot of time and almost shakes
itself to pieces.
I tried using setvbuf, with large buffers, e.g. (example only, not
checked):
#include <stdio.h>
#include <string.h>
FILE *FP1,*FP2;
#define big (32*1024*1024)
char buf1(big),buf2(big);
char a(1024),b(1024);
int i;
if(FP1=fopen("/mnt/dvd/file1","rb") == NULL) {
printf("bad fopen\n");
exit(1);
}
if(setvbuf(FP1,buf1,_IOFBF,big) {
printf("bad setvbuf\n");
exit(1);
}
if(FP2=fopen("/mnt/dvd/file2","rb") == NULL) {
printf("bad fopen\n");
exit(1);
}
if(setvbuf(FP2,buf2,_IOFBF,big) {
printf("bad setvbuf\n");
exit(1);
}
for (i=0,i<1024*1024*1024; i+=1024) {
if (fread(a,sizeof(char),1024,FP1) != 1024) {
printf("bad fread\n");
exit(1);
}
if (fread(b,sizeof(char),1024,FP2) != 1024) {
printf("bad fread\n");
exit(1);
}
... play with a and b ...
}
Why does the value of "big" have no effect on time or number of drive
shakes? What can I do instead? (e.g., are there free substitutes for
stdio that work?)
Obviously I could create
my_fopen, my_fopen64, my_fread, my_fseek, my_fseeko, my_fscanf,
my_ftell, my_getc, my_ftell...
which use the standard library calls to read large blocks sequentially
into my own buffers, but it would be silly to virtually recreate
stdio. It would also be nice to be able to efficiently use other
people's software, without substituting my routine names for all the
standard ones.
very large files from a DVD data disk, under Redhat Fedora Linux.
When this is done the DVD drive wastes a lot of time and almost shakes
itself to pieces.
I tried using setvbuf, with large buffers, e.g. (example only, not
checked):
#include <stdio.h>
#include <string.h>
FILE *FP1,*FP2;
#define big (32*1024*1024)
char buf1(big),buf2(big);
char a(1024),b(1024);
int i;
if(FP1=fopen("/mnt/dvd/file1","rb") == NULL) {
printf("bad fopen\n");
exit(1);
}
if(setvbuf(FP1,buf1,_IOFBF,big) {
printf("bad setvbuf\n");
exit(1);
}
if(FP2=fopen("/mnt/dvd/file2","rb") == NULL) {
printf("bad fopen\n");
exit(1);
}
if(setvbuf(FP2,buf2,_IOFBF,big) {
printf("bad setvbuf\n");
exit(1);
}
for (i=0,i<1024*1024*1024; i+=1024) {
if (fread(a,sizeof(char),1024,FP1) != 1024) {
printf("bad fread\n");
exit(1);
}
if (fread(b,sizeof(char),1024,FP2) != 1024) {
printf("bad fread\n");
exit(1);
}
... play with a and b ...
}
Why does the value of "big" have no effect on time or number of drive
shakes? What can I do instead? (e.g., are there free substitutes for
stdio that work?)
Obviously I could create
my_fopen, my_fopen64, my_fread, my_fseek, my_fseeko, my_fscanf,
my_ftell, my_getc, my_ftell...
which use the standard library calls to read large blocks sequentially
into my own buffers, but it would be silly to virtually recreate
stdio. It would also be nice to be able to efficiently use other
people's software, without substituting my routine names for all the
standard ones.