我做了一个数据处理的程序,可是在处理大文件数据时会因为内存不足而停止,有人告诉我可以用内存映射来处理,我是新手,跪求哪位大哥大姐,兄弟姐妹帮我一把,程序如下:unit zhcx;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, IniFiles;type
  TForm1 = class(TForm)
    Button1: TButton;
    LB1: TListBox;
    GroupBox1: TGroupBox;
    CB1: TCheckBox;
    CB2: TCheckBox;
    CB3: TCheckBox;
    CB4: TCheckBox;
    CB5: TCheckBox;
    procedure Button1Click(Sender: TObject);  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
  t,temp,t1:TStringList;
  ASource,Alien,s:TstringList;
  i:Integer;
  AppIni: TIniFile;
  str1:string;
  str2:string;
begin
    AppIni := TInifile.Create('.\config.ini');
     // HYF process
    if FileExists('.\teldata\ffy_info_hff.txt') and
    CB1.Checked then
    begin
      str1:=AppIni.ReadString('pos','HYF','');
      t:= TStringList.Create;
      t1 := TStringList.Create;
      temp:=TStringList.Create;
      temp.Delimiter:=';';
      t.LoadFromFile('.\teldata\ffy_info_hff.txt');
     // showmessage(str1);
      for i := 0 to t.Count - 1 do
      begin
        temp.DelimitedText:=t.Strings[i];
        t1.Add(Format('%20s;',[temp[3]])+
        Format('%20s;',[temp[5]])+'  ;'+'  HYF;'+
        Format('%15d;',[StrToInt(temp[1])* StrToInt(str1)div 100])+'          ;'
        +Format('%20s;',[temp[6]])+'      ;');
      end;
      t1.SaveToFile('.\teldata\deal\ffy_info_hff.txt');
      t.Free;
      t1.Free;
      temp.Free;
     // showMessage('HYF deal!');
    end;
       // CL-YFF  process
    if FileExists('.\teldata\cai_ling_info_yff.txt') and
    CB2.Checked then
    begin
      str1:=AppIni.ReadString('pre','CL','');
      str2:=AppIni.ReadString('rate','CL','');
      ASource := TStringList.Create;
      ALien := TStringList.Create;
      s:=TStringList.Create;
      ASource.LoadFromFile('.\teldata\cai_ling_info_yff.txt');
      for i := 0 to ASource.Count - 1 do
      begin
        alien.clear;
        ExtractStrings([' '], [],pchar(ASource.Strings[i]) , ALien);
        s.Add(Format('%20s;',[ALien.Strings[0]])+
        Format('%10s;',[ALien.Strings[8]])+' Y;'+'  CL;'+
        Format('%15d;',[StrToInt(ALien.Strings[7])*StrToInt(str1)*StrToInt(str2) div 10000])
        +'          ;'+Format('%20s;',[ALien.Strings[6]])+'      ;');
      end;
      s.SaveToFile('.\teldata\deal\cai_ling_info_yff.txt');
      Asource.Free;
      Alien.Free;
      s.Free;
   //   showMessage('CL-YFF deal!');
    end;     //CL-HFF    process
    if FileExists('.\teldata\cai_ling_info_hff.txt') and
    CB3.Checked then
    begin
      str1:=AppIni.ReadString('pos','CL','');
      ASource := TStringList.Create;
      ALien := TStringList.Create;
      s:=TStringList.Create;
      ASource.LoadFromFile('.\teldata\cai_ling_info_hff.txt');
      for i := 0 to ASource.Count - 1 do
      begin
        alien.clear;
        ExtractStrings([' '], [],pchar(ASource.Strings[i]) , ALien);
        s.Add(Format('%20s;',[ALien.Strings[0]])+
        Format('%10s;',[ALien.Strings[8]])+' H;'+'  CL;'+
        Format('%15d;',[StrToInt(ALien.Strings[7])*StrToInt(str1)div 100])+'          ;'+
        Format('%20s;',[ALien.Strings[6]])+'      ;');
      end;
      s.SaveToFile('.\teldata\deal\cai_ling_info_hff.txt');
      Asource.Free;
      Alien.Free;
      s.Free;
   //   showMessage('CL-HFF deal!');
    end;
      //SPDX-YFF
    if FileExists('.\teldata\phs_sms_info_down_yff.txt') and
    CB4.Checked then
    begin
      str1:=AppIni.ReadString('pre','DX','');
      str2:=AppIni.ReadString('rate','DX','');
      ASource := TStringList.Create;
      ALien := TStringList.Create;
      s:=TStringList.Create;
      ASource.LoadFromFile('.\teldata\phs_sms_info_down_yff.txt');
      for i := 0 to ASource.Count - 1 do
      begin
        alien.clear;
        ExtractStrings([' '], [],pchar(ASource.Strings[i]) , ALien);
        s.Add(Format('%20s;',[ALien.Strings[4]])+
        Format('%10s;',[ALien.Strings[5]])+' Y;'+'  SPDX;'+
        Format('%15d;',[StrToInt(ALien.Strings[10])*StrToInt(str1)*StrToInt(str2) div 10000])+'          ;'+
        Format('%20s;',[ALien.Strings[15]])+'      ;');
      end;
      s.SaveToFile('.\teldata\deal\phs_sms_info_down_yff.txt');
      Asource.Free;
      Alien.Free;
      s.Free;
   //   showMessage('SPDX-YFF deal!');
    end;
       //SPDX-HFF
    if FileExists('.\teldata\phs_sms_info_down_hff.txt')and
    CB5.Checked then
    begin
      str1:=AppIni.ReadString('pos','DX','');
      ASource := TStringList.Create;
      ALien := TStringList.Create;
      s:=TStringList.Create;
      ASource.LoadFromFile('.\teldata\phs_sms_info_down_hff.txt');
      for i := 0 to ASource.Count - 1 do
      begin
        alien.clear;
        ExtractStrings([' '], [],pchar(ASource.Strings[i]) , ALien);
        s.Add(Format('%20s;',[ALien.Strings[4]])+
        Format('%10s;',[ALien.Strings[5]])+' H;'+'  SPDX;'+
        Format('%15d;',[StrToInt(ALien.Strings[10])*StrToInt(str1) div 100])+'          ;'+
        Format('%20s;',[ALien.Strings[15]])+'      ;');
      end;
      s.SaveToFile('.\teldata\deal\phs_sms_info_down_hff.txt');
      Asource.Free;
      Alien.Free;
      s.Free;
  //    showMessage('SPDX-HFF deal!');
    end;
end;
end.

解决方案 »

  1.   

    自己来顶一个,本程序可以将处理过程简化为下面,只是不知道用内存映射该如何处理,因为要处理的'.txt'文件实在太大,大概1.5G,跪求高手~~
    unit zhcx;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls, IniFiles;type
      TForm1 = class(TForm)
        Button1: TButton;
        LB1: TListBox;
        GroupBox1: TGroupBox;
        CB1: TCheckBox;
      procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
      t,temp,t1:TStringList;
      i:Integer;
      AppIni: TIniFile;
      str1:string;
      str2:string;
    begin
        AppIni := TInifile.Create('.\config.ini');
         // HYF process
        if FileExists('.\teldata\ffy_info_hff.txt') and
        CB1.Checked then
        begin
          str1:=AppIni.ReadString('pos','HYF','');
          t:= TStringList.Create;
          t1 := TStringList.Create;
          temp:=TStringList.Create;
          temp.Delimiter:=';';
          t.LoadFromFile('.\teldata\ffy_info_hff.txt');
         // showmessage(str1);
          for i := 0 to t.Count - 1 do
          begin
            temp.DelimitedText:=t.Strings[i];
            t1.Add(Format('%20s;',[temp[3]])+
            Format('%20s;',[temp[5]])+'  ;'+'  HYF;'+
            Format('%15d;',[StrToInt(temp[1])* StrToInt(str1)div 100])+'          ;'
            +Format('%20s;',[temp[6]])+'      ;');
          end;
          t1.SaveToFile('.\teldata\deal\ffy_info_hff.txt');
          t.Free;
          t1.Free;
          temp.Free;
         // showMessage('HYF deal!');
        end;
      end.
      

  2.   

    你用的TSTRINGS太多了,晕!用流是最好的选(我的意思是:将内存映射封成流的形式)!
    你会觉得快的好多好多。