P
persres
Hello,
I couldn't find a clear answer to this question. I need a very
efficient way to read large amount of data (integers - separated by
white space and newlines). It has over a billion integers. Need to
read block by block. What is the best way to do it.
I have never been comfortable using these ifstreams as I always
assumed they were slow. Perhaps not. Could anyone advice?.
Am I better off using some Win32 API to read a file block?. Or can I
just read the say 2 MB into a buffer?
Then how do I read the the integers into the vector?. I need a really
efficient way.
So, far I only the following way -
std::vector<unsigned int> myvec;
//myvec.reserve(const_buf_ints);
std::ifstream infile("abc");
std::copy(std::istream_iterator<int>(infile),
std::istream_iterator<int>(), back_inserter(myvec));
infile.close();
However, even this is not right for me because I only want to read the
first few 1000 numbers and not the whole file. Please help.
To summarize -
1) Need to read a lot (say 100,000) of integers from a huge file
repeatedly (say with over a billion integers). What is the best way to
do that.
Thank you very much
I couldn't find a clear answer to this question. I need a very
efficient way to read large amount of data (integers - separated by
white space and newlines). It has over a billion integers. Need to
read block by block. What is the best way to do it.
I have never been comfortable using these ifstreams as I always
assumed they were slow. Perhaps not. Could anyone advice?.
Am I better off using some Win32 API to read a file block?. Or can I
just read the say 2 MB into a buffer?
Then how do I read the the integers into the vector?. I need a really
efficient way.
So, far I only the following way -
std::vector<unsigned int> myvec;
//myvec.reserve(const_buf_ints);
std::ifstream infile("abc");
std::copy(std::istream_iterator<int>(infile),
std::istream_iterator<int>(), back_inserter(myvec));
infile.close();
However, even this is not right for me because I only want to read the
first few 1000 numbers and not the whole file. Please help.
To summarize -
1) Need to read a lot (say 100,000) of integers from a huge file
repeatedly (say with over a billion integers). What is the best way to
do that.
Thank you very much