you have a bottle neck in the code you shown,
that will effectly slow your application down,
as well as use a lot more memory than is required.
If your sending small files(under a meg) then you have a good sniplet here.
if your sending very large files(over 100 megs) then try something like this.
Your loading they entire file at once,
Counting all the '\n' 's
then sending it accross the network.
So say your file load time is 5 seconds.
your counting time is next to none,
and your transfer time is 15 seconds.
that will be 20 seconds to complete a request.
You could knock that time down to 15+ seconds easly by buffering your input in a different manner.
i've added // comments // to what I added
Code:
//opened file ok....
//..
#define blocksize 1048576 // One Megabyte, 1024*1024 //
cout << "\n\nLoading file..\n";
int length = 0;
int count = 0; // moved this to before the loop //
inFile.seekg (0, ios::end);
length = inFile.tellg();
inFile.seekg (0, ios::beg);
char* buffer = NULL;
buffer = new char[blocksize];
int read; // I'm not sure if inFile.read will return a read count, because I don't know the object type //
while( !inFile.eof() ){ // loop till eof is found //
read = inFile.read(buffer, blocksize);
cout << "\n\nCounting rows..\n";
for(int i = 0; i < read; i++)
{
if(buffer[i] == '\n')
count++;
}
//your network send code.
}
inFile.close();
delete[] buffer; // I do belive this is wrong, shouldn't it be 'delete buffer'??? please someone comment
cout << "\n\nTotal Rows: " << count << "\n\n";