c++ - Boost mapped_file_source, alignment and page size -


I am trying to parse some text files in a reference up to a few hundred megabytes where performance is important, so I Parser hopes that the source will be terminated with a blank byte, so I want to see that the file size is an exact multiple of the page size (and if so, then slow, non- Memory mapped method And come back). I thought I could do this with:

  if (mf.size () & amp; (mf.alignment () - 1))  
< P> But this size turns out to be a test file with 20480, alignment is 65536 (on Windows 7, 64 bit) and the program is crashing, I guess what's happening is that the page size is really small by alignment, so My test is not working.

How do I get a page size? Or should I do something else instead? (I need a solution for both Windows and Linux, if necessary, write system specific code, but if possible, prefer portable code.)

< The simplest thing to do is to find fixing (not really very outrageous) to take the parsers to account at the end of the input.

Next: A Big Warning . Undefined ¹:

Then, just map the file using size + 1, and depend on the tracer bytes in the map (if any) are zero, and Add form NUL Terminator I do not think this is happening for the specific / undefined behavior of the forum.

In fact I just type: boost :: iostreams :: mapped_file_base :: mapmode :: priv , which is perfect for your needs:

The file to be opened with private access can be written, but these changes will not affect the underlying file []

Here is a simple snippet:

  #include & lt; Boost / iostreams / device / mapped_file.hpp & gt; # Include & lt; Fstream & gt; # Include & lt; Iostream & gt; Name space io = boost :: iostreams; Int main () {// Definitely, `State (1)` or `Promotion :: File System :: file_size (), but for Exposure: std :: streamsize const length = std :: distance ( Std :: istreambuf_iterator & lt; four & gt; (std :: ifstream ("main.cpp"). Rdbuf ()), {}); Io :: mapped_file mf ("main.cpp", io :: mapped_file_base :: mapmode :: priv, length + 1); * (Mf.end () - 1) = '\ 0'; // voicemail, faucet finished, safely, quickly and reliably std :: cout & lt; & Lt; Length & lt; & Lt; "\ N"; Std :: cout & lt; & Lt; Mf.size () & lt; & Lt; "\ N"; }  

Optional spelling:

  mf.data () [length] = '\ 0'; // voicemail, faucet finished, safely, quick and reliable * (mf.begin () + length) = 0; // etc  

¹ AFAICT This can kill a bunny or crash your process.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -