Reading a File - FASTEST WAY POSSIBLE??
Hi, Im still a bit new to programming in C++ and what imn trying to achieve is to read a file into memory as fast as possible. Here is what I do:
Code:
...
char * sMessage;
register long lSize;
FILE * fp;
if (argc)
{
fp = fopen(argv[1], "rb");
// THIS FINDS THE SIZE OF THE FILE
fseek(fp , 0 , SEEK_END);
lSize = ftell (fp);
rewind (fp);
printf("SIZE: %d\n", lSize);
// ALLOCATES NEW MEMORY FOR THE ARRAY
sMessage = new char[lSize];
// THIS IS THE PART I WANT TO SPEED UP
// I READ THE CONTENTS FROM A BINARY FILE
// ONE BYTE AT A TIME
for (i = 0; i < lSize; i++)
{
sMessage[i] = getc(fp);
}
printf("READ: %d\n", lSize);
}
return 0;
Im trying to speed up the reading process so it can read ~200Mb files in onle a couple of seconds. Does anyone have any suggestions????