最快的方法来逐行读取字符串的文本文件 [英] Fastest way to read a text file of strings line by line

查看:88
本文介绍了最快的方法来逐行读取字符串的文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

我已经看了一下,我还是不确定这个问题的答案。

I have looked around a little bit and I am still not sure of the answer to this question.

从每行的任意字读取文本文件时,从文件中读取字的绝对最快的方式是什么?

When reading from a text file with an arbitrary word on every line, what would be the absolute fastest way of reading the words from that file? The scope of the project requires the fastest possible file read.

在Windows 7上使用Visual Studio。没有跨平台的考虑。

Using Visual Studio on Windows 7. No cross platform consideration.

编辑:
请记住,这个文件读取是一次性的事情,它不会被再次读取,它不会被写入。程序启动,从文件读取,将其推入数据结构,并且不再调用loadFile()函数。

Keep in mind, this file read is a one time thing, it will not be read from again and it will not be written to. The program starts, reads from the file, pushes it into a data structure and the loadFile() function is never called again.

推荐答案

我理解你的问题,你的目标是读一个文件的文字,并将每个字插入一些数据结构。您希望此读取和插入尽可能快。 (我不会辩论这个的理由或智慧,我只接受是一个要求。:-))
如果我的理解是正确的,那么也许一个替代的方法是写一个实用程序程序,它将读取文件的文件,将它们插入数据结构,然后将该数据结构序列化为一个文件(例如BLOB.dat)。然后你的主程序将反序列化BLOB.dat到你需要的数据结构。本质上,你将单词文件预处理成一些中间二进制格式,可以最有效地加载到您的数据结构。或者这会在你的情况下作弊

As I understand your question your objective is to read a file of words and insert each word into some data structure. You want this read+insertion to be as fast as possible. (I won't debate the rationale for or the wisdom of this, I'll just accept is as a requirement. :-) ) If my understanding is correct, then perhaps an alternative approach would be to write a utility program that will read the file of words, insert them into the data structure, and then serialize that data structure to a file (say BLOB.dat, for example). Then your main program will deserialize BLOB.dat into the data structure that you require. Essentially you pre-process the words file into some intermediate binary format that can be loaded into your data structure most efficiently. Or would this be cheating in your scenario??

这篇关于最快的方法来逐行读取字符串的文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆