用C有效地读取文本的一部分++ [英] Efficiently read a portion of text in C++
问题描述
我读过这然后<一个href=\"http://stackoverflow.com/questions/17465061/how-to-parse-space-separated-floats-in-c-quickly/17479702#17479702\">this有关如何有效地读取的文本量很大(在第二个问题花车)在C ++开发的的boost ::精神
库的问题。
I've read this and then this questions about how to efficiently read big amount of text (floats in the second question) in C++ exploiting the boost::spirit
library.
这是我所看到的,在问题提出的解决上述读的全的文字,而我需要阅读的部分的输入文本(例如从CHAR X要烧焦Y)。
From what I've seen, the solutions proposed in the questions above read the whole text, while I need to read a portion of the input text (for example from char x to char y).
我可以利用上面的库用于这一目的?我怎么能有效地做到这一点,否则?
Can I exploit the library above for this purpose? How could I efficiently do it otherwise?
推荐答案
您甚至不需要映射文件的一个小节,因为MMAP只是几乎映射内存块。实际页仅按需加载,所以你可以的地图的一个文件的完整12GiB哪怕你只有比方说,物理内存4GiB(甚至不需要交换)。
You don't even need to map a subsection of the file, because mmap just virtually maps memory blocks. Actual pages are only loaded on demand, so you could map the full 12GiB of a file even if you have only, say, 4GiB of physical RAM (not even requiring swap).
如果您的文件是文本的基础上,你会想从文件中随机位置找到启动的行。
If your file is text-bases, you will want to find the start-of-line from a random location in the file.
的类似的例子是在这里的第二种方法:<一href=\"http://stackoverflow.com/questions/28217301/using-boostiostreamsmapped-file-source-with-stdmultimap/28220864#28220864\">Using提高::输入输出流:: mapped_file_source用的std :: multimap中
An example of something similar is in the second approach here: Using boost::iostreams::mapped_file_source with std::multimap
这篇关于用C有效地读取文本的一部分++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!