Klar, man muss wissen was da intern passiert und entsprechend aufpassen, aber mit dem Hinweis auf dieses prinzipielle Problem hatten wir ja angefangen!
Nun noch was zur Optimierung. Anfangs hatten wir festgestellt, dass die Pascal-Strings für dein Problem nicht einsetztbar sind, weil deine Strings zu lang sind. Wie man unschwer sieht, bestehen die Funktionen aber aus dem Setzen von Positionszeigern und anschließenden Block-Kopier-Vorgängen. Wir haben das erstmal, mit For-Schleifen realisiert. Wenn du aber wirklich lange Strings hast, dann könnte es interessant sein, diese For-Schleifen durch die Betriebssystem-Block-Kopier-Funktion CopyMemory zu ersetzen. Die Parameter sind dann wie gehabt, die Zeiger auf Zielblock-Anfang, Quellblock-Anfang und die Anzahl der zu übertragenden Bytes. Das sollte also kein Problem sein, nachdem du nun eine korrekte Version hat.
Du kannst ja mal testen, wieviel es bringt und das Ergebnis hier vorstellen.
The CopyMemory function copies a block of memory from one location to another.
Delphi-Hilfe zum Windows-SDK:
Quelltext
1: 2: 3: 4: 5:
| VOID CopyMemory ( PVOID Destination, // address of copy destination CONST VOID *Source, // address of block to copy DWORD Length // size, in bytes, of block to copy ); |
Parameters
Destination: Points to the starting address of the copied block's destination.
Source: Points to the starting address of the block of memory to copy.
Length: Specifies the size, in bytes, of the block of memory to copy.