Q&A

  • out of memory 문제.....
500 메가 정도의 TXT 파일을 원하는 파일 형태로 바꾸는 플그램인데.... out of memory  가 납니당.. 아무리 봐도 잘 모르겠습니다...... 메모리가 커지는 것을 봐서는 메모리가 새는 것 같기두 한데... 고수님들의 도움이 필요합니당.. 참 글구  밑에  function안에서 TStringList를 썼는데 free를 안해도
function 종료시에는 자동으로 해제되는 것이 맞죠?



unit pas_Hyper2Sff;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    bt_SourceFile: TButton;
    bt_Proc: TButton;
    OpenDialog1: TOpenDialog;
    Memo1: TMemo;
    procedure bt_ProcClick(Sender: TObject);
    procedure bt_SourceFileClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
    function DateTime_Proc(Input : string; CalcTime : integer) : string;
    function StringSplit(Section : string; Line : string) : TStringList;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  SourceFileList : TStringList;
implementation

{$R *.dfm}

function TForm1.DateTime_Proc(Input : string; CalcTime : integer) : string;
var DateTime : TDateTime;
begin
    TimeStamp := DateTimeToTimeStamp( (StrToDateTime(Input)) );
    TimeStamp.Time := TimeStamp.Time + 3600000 * CalcTime;

    Result := FormatDateTime('yyyymmddhhmmss', TimeStampToDateTime(TimeStamp) );
end;

function TForm1.StringSplit(Section : string; Line : string) : TStringList;
var ReturnList : TStringList;
begin
    ReturnList := TStringList.Create;


    while Pos(Section, Line) > 0 do
    begin
        ReturnList.Add( copy(Line, 1, Pos(Section, Line) - 1) );
        Line := Copy(Line, Pos(Section, Line) + 1, Length(Line) - Pos(Section, Line));
    end;

    Result := ReturnList;

end;


procedure TForm1.bt_ProcClick(Sender: TObject);
var SourceFiles : TextFile;
    WriteFiles : TextFile;
    i : integer;
    SourceLineString : String;

    dl : TStringList;

    Input : string;
    DateTime : String;
    Symbol : String;
    Value : string;
    PriceBit : String;
    Volume : String;
    IsOI : Boolean;
begin
    IsOI := False;
    dl := TStringList.Create;
    For I := 0 to SourceFileList.Count - 1 do
    begin
        AssignFile(SourceFiles, SourceFileList[i]);
        AssignFile(WriteFiles, Copy(SourceFileList[i], 1, Length(SourceFileList[i]) - 4) + '.sff');
        ReSet(SourceFiles);
        ReWrite(WriteFiles);

        While Not Eof(SourceFiles) do
        begin
            ReadLn(SourceFiles, SourceLineString);
            dl := StringSplit(',', SourceLineString);

            Symbol := dl.Strings[0];
            if Symbol = 'Symbol' then continue;
            DateTime := DateTime_Proc(dl[1] + ' ' + dl[2], 9);
            Volume := dl.Strings[4];

            if Symbol = 'Symbol' then continue;
            DateTime := DateTime_Proc(dl[1] + ' ' + dl[2], 9);
            Volume := dl.Strings[4];

            if (Length(Symbol) = 6) and (Copy(Symbol, Length(Symbol) - 2, 3) = '.KR') then
            begin
                Value := IntToStr(Round(StrToFloat(dl[3]) * 100));
                PriceBit := '2';
                IsOI := False;
            end
            else if (Length(Symbol) > 9) and (Copy(Symbol, 2, 2) = 'KS') then
            begin
                if Copy(Symbol, 1, 1) = '/' then
                begin
                    Value := IntToStr( Round(StrToFloat(dl[3])) );
                    PriceBit := '0';
                    IsOI := True;
                end;

                if Copy(Symbol, 1, 1) = '.' then
                begin
                    Value := IntToStr( Round(StrToFloat(dl[3]) * 100) );
                    PriceBit := '2';
                    IsOI := True;
                end;

            end

            else if (Copy(Symbol, 1, 1) = '/') and ( Length(Symbol) <= 8 ) then
            begin
                Value := IntToStr( Round(StrToFloat(dl[3]) * 100) );
                PriceBit := '2';
                IsOI := True;
            end

            else
            begin
                Value := IntToStr( Round(StrToFloat(dl[3])) );
                PriceBit := '0';
                IsOI := False;
            end;

            if IsOI = False then Input := DateTime + '|' + Symbol + '|' + PriceBit + '|' + Value + '|' + Volume + '|'
            else Input := DateTime + '|' + Symbol + '|' + PriceBit + '|' + Value + '|' + Volume + '|'+ '0|';

            WriteLn(WriteFiles, Input);

        end;
    end;
end;

procedure TForm1.bt_SourceFileClick(Sender: TObject);
var i : integer;
begin
    OpenDialog1.Filter := 'Text files (*.txt)|*.txt';
    if OpenDialog1.Execute then
    begin
        For I := 0 to OpenDialog1.Files.Count - 1 do
        begin
            SourceFileList.Add( OpenDialog1.Files[i] );
        end;

    end;

    Memo1.Lines := SourceFileList;


end;

procedure TForm1.FormShow(Sender: TObject);
begin
    SourceFileList := TStringList.Create;
end;

end.
2  COMMENTS