Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Memory Pre-Allocation Trick?
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
00721182
Message ID:
00722022
Vues:
34
Hi David,

>VFP is as fast as the underlying C++ code when it is doing string concatenations of the form:
>
>lcX = lcX + ...

It's certainly true that VFP is as fast as the underlying C code, however, this doesn't mean that it's fast code. VFP is actually quite slow when it comes to string handling compared to C++. The following program uses the standard approach to generate a 15 MB string:
nStart = Seconds()
lnLoop = 1024*15
lnSize = 1024
lcString = ""
For t=0 to lnLoop-1
	lcString = lcString + Replicate("A",lnSize)
Endfor 
? Seconds()-nStart
On my computer this program runs for 409 seconds which is almost 7 minutes. On the other hand, the following program does exactly the same, but it finishes in 0.731 seconds. The actually string assembling is actually only 0.281. The rest of the time is what it takes VFP to copy the result into a string variable.
Declare Long GetProcessHeap in Win32API
Declare Long HeapAlloc in Win32API Long, Long, Long
Declare memcpy in NTDLL.Dll as memcpy_write Long, String@, Long
Declare Long HeapFree in Win32API Long, Long, Long

nStart = Seconds()
lnLoop = 1024*15
lnSize = 1024
lnAddress = HeapAlloc( GetProcessHeap(), 0, lnLoop*lnSize )
For t=0 to lnLoop-1
	memcpy_write( lnAddress+(t*lnSize), Replicate("A",lnSize), lnSize )
Endfor 
? Seconds()-nStart
lcString = Sys(2600, lnAddress, lnLoop*lnSize )
HeapFree( GetProcessHeap(), 0, lnAddress )
? Seconds()-nStart
Christof
--
Christof
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform