CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Delphi >  VCL组件开发及应用

请教:文件处理的速度

楼主guesttwo(guesttwo)2002-10-10 11:59:36 在 Delphi / VCL组件开发及应用 提问

我用DELPHI处理一个结构文件,大约3000条记录,用了130毫秒,同样的功能,用VB只用了30毫秒,这是什么原因,怎么提升DELPHI处理的速度  
  DELPHI:  
   
          AssignFile(F1,   strFile);  
          Reset(F1);  
          While   Not   EOF(F1)   do  
          begin  
              Read(F1,   myrecord);  
              arrRec[lCount].***   :=   myrecord.***  
   
              If   EOF(F1)   Then  
                  break;  
              lCount   :=   lCount   +   1;  
          end;  
          CloseFile(F1);  
   
  VB:  
      Open   strFile   For   Random   As   #1   Len   =   Len(myrecord)  
      Do   While   Not   EOF(1)  
          Get   #1,   ,   myrecord          
          If   EOF(1)   Then  
              Exit   Do  
          End   If  
           
          arrRec(lCount).***   =   myrecord.***  
          lCount   =   lCount   +   1  
      Loop  
      Close   #1  
  问题点数:30、回复次数:6Top

1 楼ly_liuyang(Liu Yang LYSoft http://lysoft.7u7.net)回复于 2002-10-10 20:07:03 得分 1

定义大一些缓冲区:  
  procedure   SetTextBuf(var   F:   Text;   var   Buf   [   ;   Size:   Integer]   );  
   
  Description  
   
  In   Delphi   code,   SetTextBuf   changes   the   text   file   F   to   use   the   buffer   specified   by   Buf   instead   of   F's   internal   buffer.   F   is   a   text   file   variable,   Buf   is   any   variable,   and   Size   is   an   optional   expression.  
   
  Each   Text   file   variable   has   an   internal   128-byte   buffer   that   buffers   Read   and   Write   operations.   This   buffer   is   adequate   for   most   operations.   However,   heavily   I/O-bound   programs   benefit   from   a   larger   buffer   to   reduce   disk   head   movement   and   file   system   overhead.  
   
  Size   specifies   the   size   of   the   buffer   in   bytes.   If   Size   is   omitted,   SizeOf(Buf)   is   assumed.   The   new   buffer   remains   in   effect   until   F   is   next   passed   to   AssignFile.  
   
  SetTextBuf   can   be   called   immediately   after   Reset,   Rewrite,   and   Append,   but   never   apply   it   to   an   open   file.  
   
  When   SetTextBuf   is   called   on   an   open   file   once   I/O   operations   have   taken   place,   data   could   be   lost   because   of   the   change   of   buffer.  
   
  The   Delphi   runtime   library   does   not   ensure   that   the   buffer   exists   for   the   entire   duration   of   I/O   operations   on   the   file.   A   common   error   is   to   install   a   local   variable   as   a   buffer,   then   use   the   file   outside   the   procedure   that   declared   the   buffer.  
  ////////////////  
  Eg:  
  program   SetTextBufExample;  
   
  {$APPTYPE   CONSOLE}  
   
  var  
      Source,   Destination:   TextFile;  
      AFileName:   string;  
      AChar:   Char;  
      Buf:   array[1..32768]   of   Char;     {   32K   buffer   }  
  begin  
      Write('Enter   filename:   ');  
      Readln(AFileName);  
      AssignFile(Source,   AFileName);  
      {   Larger   buffer   for   faster   reads   }  
      SetTextBuf(Source,   Buf);  
      Reset(Source);  
      {   Dump   text   file   into   another   file   }  
      AssignFile(Destination,   'WOOF.DOG');    
      Rewrite(Destination);  
      while   not   Eof(Source)   do  
   
      begin  
          Read(Source,   AChar);  
          Write(Destination,   AChar);  
      end;  
      CloseFile(Source);  
      CloseFile(Destination);  
  end.Top

2 楼guesttwo(guesttwo)回复于 2002-10-11 10:46:08 得分 0

结构文件!!Top

3 楼smilelhh(blue)回复于 2002-10-11 12:11:30 得分 14

If   EOF(F1)   Then               break;  
  这一行不要试试.  
  其它不知道  
  Top

4 楼wxjh(农民)回复于 2002-10-11 12:14:30 得分 5

使用内存映射文件Top

5 楼blazingfire(烈焰)(对.net极度憎恨中....)回复于 2002-10-11 12:28:10 得分 10

用记录流来处理它封装了内存映射文件Top

6 楼guesttwo(guesttwo)回复于 2002-10-11 21:34:46 得分 0

可以详细一点吗?Top

相关问题

  • 文件处理的 速度
  • 请教:文件处理的速度
  • 如何提高文件处理及打印的速度?
  • 一个关于dx中模型文件处理速度的问题
  • about 文件处理
  • 批处理文件
  • 批处理文件
  • bmp 文件处理
  • 批处理文件
  • 让很多都头疼的问题。 用VB处理100M以上的大文件如何加快速度?

关键词

  • delphi
  • myrecord
  • lcount
  • 处理
  • eof
  • buffer
  • variable
  • buf
  • text file

得分解答快速导航

  • 帖主:guesttwo
  • ly_liuyang
  • smilelhh
  • wxjh
  • blazingfire

相关链接

  • Delphi类图书
  • Delphi类源码下载
  • Delphi控件下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo