I'm pretty sure now, that constantly calling cin for every character (8 bytes) caused a lot of unnesseccary overhead. I read the data files all at once, and they are now processed almost as fast as they are generated. =)
I modified code to copy a file and here is the result:
Code:
// Copy a file
#include <fstream>
using namespace std;
int main () {
char * buffer;
char * buffer2;
long size;
int i = 0, j = 0;
ifstream infile ("test.txt",ifstream::binary);
ofstream outfile ("new.txt",ofstream::binary);
// get size of file
infile.seekg(0,ifstream::end);
size=infile.tellg();
infile.seekg(0);
// allocate memory for file content
buffer = new char [size];
buffer2 = new char [size/2];
// read content of infile
infile.read (buffer,size);
// filter every other byte
while(i != size)
{if((i%2) < 1)
{buffer2[j] = buffer[i];
i++; j++;
}
else if((i%2) >= 1)
{i++;}
else {exit(-1);}
}
// write to outfile
outfile.write (buffer2,size/2);
// release dynamically-allocated memory
delete[] buffer;
delete[] buffer2;
outfile.close();
infile.close();
return 0;
}