Saturday, July 25, 2009

Reading big files using ifstream::read

I am reading very big files using fstream::read. I first read to my internal cache using command

object.read((char*)char_buffer,current_cache_size)

When trying cache > 2048 Mb, the program is stuck.

OK, the trick is that

istream& read ( char* s, streamsize n );

where

"streamsize" is an implementation-defined synonym of one of the signed basic integral types (generally signed int or signed long). So I am apparently having "signed int" implementation:

2^(32-1) == 2048*1024*1024

So I have to read in smaller blocks and then fill up my cache...

0 comments:

Post a Comment