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:
00722508
Views:
36
Stephane,

In the context of the original message, it really doesn't matter what character fills the buffer.

For all cases where I'm doing things like building HTML stings, simple string concatenations or the TEXTMERGE commands are fast enough. When you are adding strings it does make sense to optimize things. I know I improved the performance of the WWXML code by about 50% in some of the methods by hoisting invariants out of the loop and using some smaller temp strings rather than always concatenating every little piece to the final result. Something along the lines of:
lcResult = "<table>"
n = afields( laFields )
scan
   lcRow = "<tr>"
   for i = 1 to n
      lcRow = lcRow + "<td>" + transform( eval( laFields[i,1] ) ) + "</td>"
   endfor
   lcResult = lcResult + lcRow + "</tr>"
endscan

lcResult = lcResult + "</table>"
So this way the one big string only gets extended once per row of data rather than for every field. The code below shows a really slow way of doing the same thing:
lcResult = "<table>"
scan
   n = afields( laFields )
   lcResult = lcResult + "<tr>"
   for i = 1 to n
      lcResult = lcResult + "<td>" + 
      lcResult = lcResult + transform( eval( laFields[i,1] ) )
      lcResult = lcResult + "</td>"
   endfor
   lcResult = lcResult + "</tr>"
endscan

lcResult = lcResult + "</table>"
If you are building lots of strings over several hundred K in size and absolute performance is an issue you might want to look at using a C++ DLL from VFP. There's a couple of examples on my website that show how C++ can really beat the pants off VFP for some string operations.


>I don't use a 15 MB string of "A" very often in my programs :), the problem arise when you want to build a string with different values in a loop.
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform