Thema: Delphi Code Optimization

Einzelnen Beitrag anzeigen

sdean

Registriert seit: 5. Dez 2009
64 Beiträge
 
#1

Code Optimization

  Alt 9. Mai 2011, 17:31
Delphi-Version: 7
Hi i've these functions to Store Streams in One File :
Delphi-Quellcode:
function AddData(ID:string; pBuf: Pointer; Count: Integer): Integer;
var
  Buff : Pointer;
begin
 // FFile is of Type : TFileStream
  FFile.Seek(0, soFromEnd);//--> the Container *
  if( Result > -1 )then
  begin
   GetMem(Buff, Count);
   try
    Move(pBuf^, Buff^, Count);
    Result := FFile.Write(Buff^, Count);
   finally
    FreeMem(Buff, Count);
   end;
  end;
end;
{* and here how i add Streams *}
function InsertStream(ID: String;aStream: TStream): Integer;
var
  pBuff : Pointer;
begin
  // alloc Mem for pBuff
  GetMem(pBuff, aStream.Size);
  try
   aStream.Position := 0;
   aStream.Read(pBuff^, aStream.Size);
   // now add data
   Result := AddData(ID, pBuff, aStream.Size);
  finally
   FreeMem(pBuff, aStream.Size);
  end;
end;
my question is :
how could i optimize the InsertStream Function so that it can work fast for file's size more than 1 GB cause i cannot load such a huge size in Memory.


many thanks in advance
  Mit Zitat antworten Zitat