Z
ZafT
Thanks in advance for any tips that might get me going in the right
direction.
I am working on a simple exercise for school that is supposed to use read to
read a file (about 10 MB). I am supposed to change the buffer size and see
how this affects the read time. In other words, the buffer is supposed to
limit how much of the file gets read per call, and cause some change in
speed. I am supposed to do the same with fread as well, but I'm just asking
for help on read for now.
Everything works like a charm if I have the buffer set to the same size as
the file, but if I make the buffer size smaller than the file, I get a core
dump - segmentation fault.
Here's all the code. Do I need to put the data somewhere or clear the
buffer after a pass or something? I'm guessing I'm stepping out of my
buffer when it gets full.
#include <fstream>
#include <time.h>
#include <iostream>
using namespace std;
void main(){
cout << "start \n" ;
char buff[100];
int length;
time_t seconds;
ifstream inputFile ("TEST", ios::binary);
inputFile.seekg (0, ios::end);
length = inputFile.tellg();
inputFile.seekg (0, ios::beg);
seconds = time (NULL);
cout << seconds << " Seconds at start \n" << length << " bytes\n" ;
// If buffer is same size as the file, I have no problem, but if I
drop the buff size - CRASH!
while(inputFile.read(buff,10000000)){
}
seconds = time(NULL);
cout << seconds << " Seconds at finish \n" ;
}
Any help is appreciated!
Shane
direction.
I am working on a simple exercise for school that is supposed to use read to
read a file (about 10 MB). I am supposed to change the buffer size and see
how this affects the read time. In other words, the buffer is supposed to
limit how much of the file gets read per call, and cause some change in
speed. I am supposed to do the same with fread as well, but I'm just asking
for help on read for now.
Everything works like a charm if I have the buffer set to the same size as
the file, but if I make the buffer size smaller than the file, I get a core
dump - segmentation fault.
Here's all the code. Do I need to put the data somewhere or clear the
buffer after a pass or something? I'm guessing I'm stepping out of my
buffer when it gets full.
#include <fstream>
#include <time.h>
#include <iostream>
using namespace std;
void main(){
cout << "start \n" ;
char buff[100];
int length;
time_t seconds;
ifstream inputFile ("TEST", ios::binary);
inputFile.seekg (0, ios::end);
length = inputFile.tellg();
inputFile.seekg (0, ios::beg);
seconds = time (NULL);
cout << seconds << " Seconds at start \n" << length << " bytes\n" ;
// If buffer is same size as the file, I have no problem, but if I
drop the buff size - CRASH!
while(inputFile.read(buff,10000000)){
}
seconds = time(NULL);
cout << seconds << " Seconds at finish \n" ;
}
Any help is appreciated!
Shane