Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Memory Pre-Allocation Trick?
Message
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00721182
Message ID:
00722028
Views:
31
Christof,

Pretty impressive !

I am using a different approach which is much faster than your first example but slower than your second example. The good thing about my approach is you don't need to know the final size of the string. Is there a way to use your
approach whithout knowing the memory size to allocate ?
nStart = Seconds()
lnLoop = 1024*15
lnSize = 1024
lcString = ""
lcFile = Addbs(Sys(2023))+Sys(2015)
lnHandle = Fcreate( lcFile )
For t=0 to lnLoop-1
	=Fwrite( lnHandle, Replicate("A",lnSize) )
Endfor 
=Fclose(lnHandle)
lcString = FileToStr( lcFile )
Erase (lcFile)
? Seconds()-nStart
>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform