从文件读取问题 [英] Problem reading from a file

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

问题描述

你好朋友,

我是用C#进行的初学者编程,我正在开发一个项目,该项目应该从Route Views Internet路由表中读取IP地址并将其与所在国家/地区(通过其ASN)关联,并输出IP数量.每个国家/地区.

到目前为止,我已经完成了大部分项目,但是还有一个大问题,路由表中的文件很大.它约为600 MB.我提取了该文件的一部分(使用gVim)进行测试,一切正常.但是,当我尝试从真实的内容中读取内容时,它就冻结了.

我正在使用TextReader ...

Hello friends,

I''m a beginner programming in C#, and I am developing a project that is supposed to read the IP addresses from a Route Views Internet routing table and relate them to their country (via their ASN), having as an output the amount of IP''s per country.

So far, I have most of the project fairly done, but I have one little big problem, the file with the routing table is HUGE. It is about 600 MB. I extracted a portion of this file (using gVim) to make tests, and everything works fine. But when I try to read from the real one, it just freezes.

I am using a TextReader...

TextReader tx = new StreamReader(path_to_file);



...并逐行迭代(将近600万行)以识别它是否是IP地址并将其存储在数据结构中,以供进一步分析.

当我编译运行时,什么也没有发生. X |它只是冻结,窗口显示无响应",并且没有输出或错误.我已经离开了大约3个半小时,没有任何运气.

非常感谢您的所有帮助:)



... and iterating line by line (of almost 6 million lines) to identify if it is an IP address and store it in a data structure, for further analysis.

When I compile and run, nothing happens. X| It just freezes, the window shows "not responding", and no output nor errors are shown. I already left it about 3 hrs and a half without any luck.

Thanks a lot for all your help :)

推荐答案


如果该文件被其他进程共享,则可能导致访问该文件的速度变慢.如果您正在从GUI线程读取大文件,则它可能会冻结窗口(如果它是基于GUI的应用程序).如果是这样,您可以从单独的线程读取文件,也可以显示读取进度.

我认为我们可以通过一次读取操作读取大数据来改善文件访问.例如1 MB或更多.


谢谢与问候
Radhakrishnan G.
Hi
If that file is shared by other processes it may cause slow to access the file, If you are reading the big file from the GUI thread it may freeze the window( if it is GUI based application). If so you can read the file from a separate thread and also possible to show the progress of the reading.

I think we can improve the file access by reading large data in one read operation. eg 1 MB or more.


Thanks & Regards
Radhakrishnan G.


alemangui写道:
alemangui wrote:

它只是冻结,窗口显示无响应",

It just freezes, the window shows "not responding",



这表明您的应用程序需要在后台线程上读取/解析文件,而使UI线程保持空闲状态.

如果您是我,那么我会考虑使用.NET配置文件工具,例如jetBrains dotTrace [ ^ ]或RedGate ANTS [



This suggests that your application needs to read/parse the file on a background thread, leaving the UI thread free.

If I were you, I''d look at using a .NET profile tool such as jetBrains dotTrace[^] or RedGate ANTS[^] and see what''s actually going on in your code. You are probably making lots and lots of calls to the same piece of code, some of which you might be able to find optimisations for.


非常感谢您的快速响应!

我看到我必须创建后台线程来读取文件,甚至可能管理进度条以确保它确实在做某事,我将尝试这样做并通知您.

一个问题,关于每个读取操作获得大约1MB的存储空间,是如何实现的?

再次感谢:D
Thanks a lot for your fast response!

I see I have to create background thread to read the file, and possibly even manage a progress bar to make sure it is actually doing something, I will try this and keep you informed.

One question, as for getting about 1MB per read operation, how is that achieved?

Thanks again :D


这篇关于从文件读取问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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