使用TStringList加载巨大的文本文件是Delphi中的最佳方法吗? [英] Is using TStringList to load huge text file the best way in Delphi?

查看:538
本文介绍了使用TStringList加载巨大的文本文件是Delphi中的最佳方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在delphi中加载大量文本文件数据的最佳方法是什么?是否有可以超快加载文本文件的组件?

What is the best way to load huge text file data in delphi? Is there any component that can load text file superfast?

假设我有一个文本文件,其中包含数据库并以固定长度格式存储。
它包含150个字段,每个字段至少50个字符。
1.我需要将其加载到内存
2.我需要对其进行解析,并可能将其存储在memdataset中以进行处理

Let's say I have a text file contains database and stored in fix length format. It contains 150 field with each at least 50 characters. 1. I need to load it into memory 2. I need to parse it and probably store it in a memdataset for processing

我的问题:
1.如果我使用TStringList.loadFromFile方法就足够了吗?
2.还有其他更好的组件来操纵文本文件吗?
3.我应该从文本文件中使用低级读取吗?

My questions: 1. Is it enough if I use TStringList.loadFromFile method? 2. Is there any other better component to manipulate the text file? 3. Should I use low level reading from textfile?

谢谢您。

推荐答案

TStringList从来不是处理大量文本的最佳方法,但它是最简单的。如果您手头上有小文件,则可以使用TStringList而不会出现问题。即使您有大文件(不是大文件),也可以使用TStringList来实现您算法的一个版本以进行测试,因为它很容易理解。

TStringList is never the optimal way of working with lots of text, but it's the simplest. If you've got small files on your hands you can use TStringList without issues. Even if you have large files (not huge files) you might implement a version of you algorithm using TStringList for testing purposes, because it's simple and easy to understand.

文件很大,因为您将它们称为数据库,所以它们可能很大,因此您需要研究替代技术,这些技术可使您仅从数据库中读取所需的内容。调查:

If your files are large, as they probably are since you call them "databases", you need to look into alternative technologies that will enable you to read only as much as you need from the database. Look into:


  • TFileStream

  • 内存映射文件。

不要看在Delphi中仍然可以使用的基于文件的旧API,它们已经很老了。

Don't look at the old "file" based API's still available in Delp they're plain old.

由于我们最近在SO上存在两个类似的问题,因此我不会详细介绍如何使用这些方法访问文本:

I'm not going to go into details on how to access text using those methods because we've recently had two similar questions on SO:

如何有效地阅读第一本在Delphi中许多文件的行

使用Delphi快速搜索以查看大文件中是否存在字符串

这篇关于使用TStringList加载巨大的文本文件是Delphi中的最佳方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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