从文件访问数据的最快方法。 [英] Fastest way to access data from a file.

查看:70
本文介绍了从文件访问数据的最快方法。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我正在开发一个桌面应用程序,需要将一些数据存储在

本地文件中。比方说,我想在一个文件中有一个带有

名称和电话号码的地址簿。我希望能够通过尽可能快地搜索给定的电话号码来检索

名称。


我考虑过使用XmlTextReader的可能性类似于:


< list>

< item number =" 1234567">

< name> ; John Doe< / name>

< / item>

< item number =" 9876 *">

< ;名称> Jane Doe< / name>

< / item>

< / list>


或简单带有以特殊字符分隔的条目的文本文件:


1234567~John Doe%9876 * ~Jane Doe%


然后使用Split(" ;%" .ToCharArray())获取一个项目数组,然后

在每个项目上拆分(〜.ToCharArray())以获取名称和编号。


我这个数据库将有大约200个条目(这个

例子中的名称和数字),所以我想知道你认为哪个将执行紧固对于大多数配置来说,
和更好。


提前谢谢。


IgnacioX.Domínguez

解决方案

我会推荐一种XML方法。

如果数据文件估计不是很大,我会

使用DOM方法(XmlDocument)。

比你可以执行XPath评估,如果使用它们会很快

有效,

查找特定记录。

数据文件在文本编辑器中查看时也很有意义,

可能很容易调试/监控数据。


-

问候,

DennisJDMyrén

奥斯陆Kodebureau

" IgnacioX.Domínguez" < IG ******* @ cantv.net>在消息中写道

新闻:%2 *************** @ tk2msftngp13.phx.gbl ...

嗨。我正在开发一个桌面应用程序,需要在
本地文件中存储一些数据。比方说,我想在一个文件中有一个带有
名称和电话号码的地址簿。我希望能够通过尽可能快地搜索给定的电话号码来检索
名称。

我已经考虑过使用XmlTextReader和
之类的可能性:
< list>
< item number =" 1234567">
< name> John Doe< / name>
< / item>
< item number =" 9876 *">
< name> Jane Doe< / name>
< / item>
< / list>

或一个简单的文本文件,条目由特殊字符分隔:

1234567~John Doe%9876 * ~Jane Doe%

然后使用Split(&%; " .ToCharArray())获取一个项目数组,然后在每个项目上分割(〜.ToCharArray())以获取名称和编号。

我这个数据库将有大约200个条目(这个例子中的名称和数字),所以我想知道你认为哪一个会在大多数配置上更快更好地执行


T.提前告诉你。

IgnacioX.Domínguez



嗨tocayo :)


最快的方法是将它放在内存中,你可以用

两个成员(名字,数字)创建一个结构,并有一个它们的ArrayList ..你在

开始,然后全部来自内存。


如果由于某种原因你不能将它们放在内存中最好的方式是

保留文本文件而不是XML,在文本文件中保存每条

行一条记录,并使用特殊字符划分字段。为了进一步提高性能

你应该首先放置你要搜索的字段,然后将它固定为

长度。通过这种方式你可以使用String.SubString而不是String.Split


Ayway,最好的办法是将它们全部留在内存中。即便如此,我认为

XML在这里并不是一个好主意。


干杯,


-

Ignacio Machin,

ignacio.machin at dot.state.fl.us

佛罗里达州交通局


" IgnacioX.Domínguez" < IG ******* @ cantv.net>在消息中写道

新闻:%2 *************** @ tk2msftngp13.phx.gbl ...

嗨。我正在开发一个桌面应用程序,需要在
本地文件中存储一些数据。比方说,我想在一个文件中有一个带有
名称和电话号码的地址簿。我希望能够通过尽可能快地搜索给定的电话号码来检索
名称。

我已经考虑过使用XmlTextReader和
之类的可能性:
< list>
< item number =" 1234567">
< name> John Doe< / name>
< / item>
< item number =" 9876 *">
< name> Jane Doe< / name>
< / item>
< / list>

或一个简单的文本文件,条目由特殊字符分隔:

1234567~John Doe%9876 * ~Jane Doe%

然后使用Split(&%; " .ToCharArray())获取一个项目数组,然后在每个项目上分割(〜.ToCharArray())以获取名称和编号。

我这个数据库将有大约200个条目(这个例子中的名称和数字),所以我想知道你认为哪一个会在大多数配置上更快更好地执行


T.提前告诉你。

IgnacioX.Domínguez



嗨Dennis,

如果估计数据文件不是很大,我会使用DOM方法(XmlDocument)。


我平均会有大约200个条目,有些情况下可能是b / b
的两倍。你认为在这种情况下使用XmlDocument比使用

XmlTextReader更好吗?或相反亦然?这些是否将整个XML文件加载到

内存中?

您可以执行XPath评估,如果有效使用它们会很快,


最有效的使用方式是什么?

提前致谢。


DennisMyrén <德**** @ oslokb.no>在消息中写道

新闻:O7 ******************* @ news2.e.nsc.no ...我会推荐一种XML方法。
如果数据文件估计不是很大,我会使用DOM方法(XmlDocument)。
你可以执行XPath评估,如果使用它们会很快在文本编辑器中查看时,数据文件也很有意义,这可能很容易调试/监控数据。 />
-
问候,
DennisJDMyrén
Oslo Kodebureau
IgnacioX.Domínguez < IG ******* @ cantv.net>在消息中写道
新闻:%2 *************** @ tk2msftngp13.phx.gbl ...

嗨。我正在开发一个桌面应用程序,需要在


本地文件中存储一些数据。比方说,我想在一个文件中有一个带有
名称和电话号码的地址簿。我希望能够通过尽可能快地搜索给定的电话号码来检索
名称。

我已经考虑过使用XmlTextReader的可能性


喜欢:


< list>
< item number =" 1234567">
< name> John Doe< / name>
< / item>
< item number =" 9876 *">
< name> Jane Doe< / name>
< / item>
< / list>

或带有以特殊字符分隔的条目的简单文本文件:

1234567~John Doe%9876 * ~Jane Doe%

然后使用Split("%" .ToCharArray())获取一系列项目,然后在每个项目上拆分(〜.ToCharArray())获取姓名和号码的项目。

我这个数据库将有大约200个条目(这个例子中的名称和数字),所以我想知道你认为哪一个会执行
更快

并且在大多数配置上都更好。

提前谢谢。

IgnacioX.Domínguez




Hi. I''m developing a desktop application that needs to store some data in a
local file. Let''s say for example that I want to have an address book with
names and phone numbers in a file. I would like to be able to retrieve the
name by searching for a given phone number the fastest I can.

I have considered the posibility of using XmlTextReader with something like:

<list>
<item number="1234567">
<name>John Doe</name>
</item>
<item number="9876*">
<name>Jane Doe</name>
</item>
</list>

or a simple text file with entries separated by special characters:

1234567~John Doe%9876*~Jane Doe%

and then use Split("%".ToCharArray()) to get an array of items, and then
Split("~".ToCharArray()) on every item to get name and number.

I this database will have around 200 entries (name and number in this
example), so I would like to know which one do you think will perform faster
and better on most configurations.

Thank you in advance.

Ignacio X. Domínguez

解决方案

I would recommend an XML approach.
If the data file is not estimated to be gigantic, I would
use a DOM approach (XmlDocument).
Than you can perform XPath evaluations, which are fast if they are used
efficiently,
to find specific records.
And the data file also makes great sense when viewing in a text editor,
which may be good for debugging/monitoring the data easily.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Ignacio X. Domínguez" <ig*******@cantv.net> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...

Hi. I''m developing a desktop application that needs to store some data in a local file. Let''s say for example that I want to have an address book with
names and phone numbers in a file. I would like to be able to retrieve the
name by searching for a given phone number the fastest I can.

I have considered the posibility of using XmlTextReader with something like:
<list>
<item number="1234567">
<name>John Doe</name>
</item>
<item number="9876*">
<name>Jane Doe</name>
</item>
</list>

or a simple text file with entries separated by special characters:

1234567~John Doe%9876*~Jane Doe%

and then use Split("%".ToCharArray()) to get an array of items, and then
Split("~".ToCharArray()) on every item to get name and number.

I this database will have around 200 entries (name and number in this
example), so I would like to know which one do you think will perform faster and better on most configurations.

Thank you in advance.

Ignacio X. Domínguez



Hi tocayo :)

The fastest way is to having it in memory, you could create a struct with
two members ( name, number) and have an ArrayList of them.. you read them at
the beggining and after that all is from memory.

if for some reason you cannot have them in memory the best way would be
keeping a text file, not a XML, in the text file you keep one record per
line, and divide the fields using a special char. For further performance
you should put the field you will search for first and make it a fixed
length. in this way you can use String.SubString instead of String.Split

Ayway , the best way is to keep them all in memory. even so I think that the
XML is not very good idea here.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Ignacio X. Domínguez" <ig*******@cantv.net> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...

Hi. I''m developing a desktop application that needs to store some data in a local file. Let''s say for example that I want to have an address book with
names and phone numbers in a file. I would like to be able to retrieve the
name by searching for a given phone number the fastest I can.

I have considered the posibility of using XmlTextReader with something like:
<list>
<item number="1234567">
<name>John Doe</name>
</item>
<item number="9876*">
<name>Jane Doe</name>
</item>
</list>

or a simple text file with entries separated by special characters:

1234567~John Doe%9876*~Jane Doe%

and then use Split("%".ToCharArray()) to get an array of items, and then
Split("~".ToCharArray()) on every item to get name and number.

I this database will have around 200 entries (name and number in this
example), so I would like to know which one do you think will perform faster and better on most configurations.

Thank you in advance.

Ignacio X. Domínguez



Hi Dennis,

If the data file is not estimated to be gigantic, I would
use a DOM approach (XmlDocument).
I would have around 200 entries in average, in some cases maybe twice that
number. Do you think using XmlDocument in this case is better than using
XmlTextReader? or viceversa? Does these load the entire XML file into
memory?
Than you can perform XPath evaluations, which are fast if they are used
efficiently,
What is the most efficient way of using it?
Thanks in advance.

"Dennis Myrén" <de****@oslokb.no> wrote in message
news:O7*******************@news2.e.nsc.no...I would recommend an XML approach.
If the data file is not estimated to be gigantic, I would
use a DOM approach (XmlDocument).
Than you can perform XPath evaluations, which are fast if they are used
efficiently,
to find specific records.
And the data file also makes great sense when viewing in a text editor,
which may be good for debugging/monitoring the data easily.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Ignacio X. Domínguez" <ig*******@cantv.net> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...

Hi. I''m developing a desktop application that needs to store some data in


a

local file. Let''s say for example that I want to have an address book
with
names and phone numbers in a file. I would like to be able to retrieve
the
name by searching for a given phone number the fastest I can.

I have considered the posibility of using XmlTextReader with something


like:


<list>
<item number="1234567">
<name>John Doe</name>
</item>
<item number="9876*">
<name>Jane Doe</name>
</item>
</list>

or a simple text file with entries separated by special characters:

1234567~John Doe%9876*~Jane Doe%

and then use Split("%".ToCharArray()) to get an array of items, and then
Split("~".ToCharArray()) on every item to get name and number.

I this database will have around 200 entries (name and number in this
example), so I would like to know which one do you think will perform


faster

and better on most configurations.

Thank you in advance.

Ignacio X. Domínguez




这篇关于从文件访问数据的最快方法。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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