boost mapped_file issue

Hi all, I try to use memory map file. However, I don't know why the readsome return 0. It is fine if I use getline. int main(int argc,char *argv[]) { boost::iostreams::mapped_file_source source(argv[1]); boost::iostreams::stream<boost::iostreams::mapped_file_source> input(source); while(!input.eof()) { char b[1]; streamsize iRet = input.readsome(b, 1); cout << iRet << endl; cout << b[iRet]; } //std::string line; //while(std::getline(input, line)) { // std::cout << "Line: " << line << std::endl; //} return 1; } -- View this message in context: http://boost.2283326.n4.nabble.com/boost-mapped-file-issue-tp3971495p3971495... Sent from the Boost - Dev mailing list archive at Nabble.com.

On Tue, Nov 01, 2011 at 06:39:18PM -0700, dophine wrote:
Hi all,
I try to use memory map file. However, I don't know why the readsome return 0. It is fine if I use getline.
readsome on streams is generally a suboptimal idea unless you ensure that somehow, there's data in the rdbuf. If it's empty, readsome will not ever produce anything new. Personally, I really dislike the choice of "some" in the function name, as it for some reason makes it the first choice for people who don't know the difference between read and readsome. Unless you need the non-blockingness of readsome and are prepared to handle all the work around it, use read. Also note that eof() won't be true until _after_ a read past the end has failed, so your iteration, had it worked, would have erroneously processed one iteration too much. -- Lars Viklund | zao@acc.umu.se

Thank you. Do you have any suggestion on how to read the data from the map_file? -- View this message in context: http://boost.2283326.n4.nabble.com/boost-mapped-file-issue-tp3971495p3972398... Sent from the Boost - Dev mailing list archive at Nabble.com.
participants (2)
-
dophine
-
Lars Viklund