Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Help with "read" issue please

Thread Tools

Help with "read" issue please

Thomas Matthews
Posts: n/a
ZafT wrote:

> .............
>>So don't assume that
>>char buf[100];
>>while (, 100))
>>results in bytes being phyically read 100 at a time from the file.
>>Another thing to be aware of it that on some operating systems you could
>>get different results on different occasions. For instance it could be
>>that if you run your program twice it will run faster the second time.
>>This is because the operating system is 'remembering' that you read the
>>file before and so storing part or all of the file in memory assuming that
>>you will want to read it again. Another case of buffering.

> It's like you were reading my mind. I was just wondering why it ran so much
> faster the second time. heh. Well it seems as though this experiment for
> comparing read and fread is not going to give any kind of raw result.
> That's okay though. I've learned a few things tonight. I appreciate your
> time very much. This group has been good to me as long as I try everything
> myself first and post enough code so people don't have to read my mind.

#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std; // for toy programs.

const unsigned int MAX_BUFFER_SIZE = 50000;
const unsigned int chunk_sizes[] =
1, 2, 5, 10, 20, 50, 100, 200, 500,
1000, 2000, 5000, 10000, 20000, 50000
const unsigned int NUM_CHUNK_SIZES =
sizeof(chunk_sizes) / sizeof(chunk_sizes[0]);

unsigned char buffer[MAX_BUFFER_SIZE];

int main(void)
ifstream data_file;

for (unsigned int i = 0; i < NUM_CHUNK_SIZES; ++i)
unsigned int chunk_size = chunk_sizes[i];*...*/); // Per requirements.
while (, chunk_size))
// Do stuff here.
data_file.close(); // Per requirements.

If your compiler cannot allocate an automatic array
of 50,000 then you will have to use the new operator
and allocate memory before you start reading. I
highly recommend allocating the largest size and only
do this once.

Thomas Matthews

C++ newsgroup welcome message:
C++ Faq:
C Faq:
alt.comp.lang.learn.c-c++ faq:
Other sites: -- C++ STL Library book

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Please please please help this guy with his open source java app Java 4 05-05-2005 08:24 AM
Console profile for Windows app in VC++ - PLEASE PLEASE PLEASE HELP! MuZZy C++ 7 01-07-2005 08:40 PM
Computer problems please please please help Nick Computer Support 0 06-04-2004 08:49 PM
HELP! HELP! PLEASE, PLEASE, PLEASE tpg comcntr Computer Support 11 02-15-2004 06:22 PM
please help... learn C++ please please please :) KK C++ 2 10-14-2003 02:08 PM