AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Code Optimization

Ein Thema von sdean · begonnen am 9. Mai 2011 · letzter Beitrag vom 10. Mai 2011
 
FredlFesl

Registriert seit: 19. Apr 2011
293 Beiträge
 
Delphi 2009 Enterprise
 
#2

AW: Code Optimization

  Alt 9. Mai 2011, 19:48
The Code contains errors and redundant stuff.
Here's my improved / modified and untested version.
Delphi-Quellcode:
Const
  BLOCKSIZE = 1024*1024; // Write in chunks @ 1MB

function AddData(ID:string; pBuf: Pointer; Count: Integer): Integer;
begin
  FFile.Seek(0, soFromEnd);
  if( Result > -1 )then // ***** WHERE DOES THIS Result COME FROM? if you leave it Like this, it will not work.
    Result := FFile.Write(PAnsiChar(pBuf)^, Count);
end;

function InsertStream(ID: String;aStream: TStream): Integer;
var
  pBuff : Pointer;
  BytesRead : Integer;

begin
  GetMem(pBuff, BLOCKSIZE); // allocate a chunk of memory
  try
   aStream.Position := 0;
   Repeat
     BytesRead := aStream.Read(pBuff^, MIN (BLOCKSIZE, aStream.Size - aPosition)); // move data into the chunk
     Result := AddData(ID, pBuff, BytesRead); // Add the chunk to the file
   Until (Result<>0) or (BytesRead < BLOCKSIZE);
  finally
   FreeMem(pBuff, BLOCKSIZE);
  end;
end;
However, a much simpler approach would be
Delphi-Quellcode:
FFile.Seek(0, soFromEnd);
FFile.CopyFrom (aStream, FFile.Position);
Das Bild hängt schief.
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:37 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz