Working with pointers is faster than working with variables.
On the other hand, what kind of program do you have that's it's so critical for you to save even some milliseconds ?
It may solve any speed problems for you.
 
Dimitris Botsis
 
----- Original Message -----
From: WOODE Soft
Sent: Thursday, May 04, 2006 11:59 AM
Subject: [advanced_delphi] Swapping strings

Hi!

I've read on a VB-website that swapping strings in the manor below is a very slow method:

var st1,st2, tmp: strings;

tmp:=st1;
st1:=st2;
st2:=tmp;

I've found this VB code on the site, the author claims it to be about 25 times faster (with lots of data to swap):

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As _
    Any, source As Any, ByVal numBytes As Long)

Dim saveAddr As Long

' save the descriptor of first string
saveAddr = StrPtr(s1)
' copy the s2's descriptor into s1's descriptor (32 bit)
CopyMemory ByVal VarPtr(s1), ByVal VarPtr(s2), 4
' complete the swapping of descriptors
CopyMemory ByVal VarPtr(s2), saveAddr, 4

The problem is a don't speak "VB" and i don't really know how to translate this into Pascal.

And is it really faster?

/Michael Woode

______________________________
 


Sudoku i mobilen? Klicka här

SPONSORED LINKS
Basic programming language C programming language Computer programming languages
The c programming language C++ programming language Software programming language


YAHOO! GROUPS LINKS




Reply via email to