Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Interesting string behavior
Message
From
19/07/1999 17:37:03
Gary Foster
Pointsource Consulting LLC
Chanhassen, Minnesota, United States
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Interesting string behavior
Miscellaneous
Thread ID:
00243326
Message ID:
00243326
Views:
44
To all,
I thought I'd pass along some interesting string manipulation behaviors I discovered trying to deal with arrays passed by reference from COM clients. I have 50k strings that need to go back and forth to COM clients. Under Japanese Windows, BSTR's go kaflooy(highly technical engineering term). We realized that safearray's are the way to go. I started filling the arrays with a simple loop but it takes a LONG time. After much flailing about, I noticed that looping and SUBST()'ing a table field was much faster than a memory variable. This is counter intuitive to me to say the least! Anyway, here is some quick code to illustrate what I found. Maybe you'll find it interesting.

Gary Foster


DIMENSION MyArray[50000]
MyArray = chr(0)
DO Compare witt MyArray


PROCEDURE Compare
LPARAMETER taPassedArray

LOCAL cDataString
LOCAL nStrLen
LOCAL aa
LOCAL bb
LOCAL nInc

EXTERNAL ARRAY taPassedArray

*-- Fake up a string. I would normally get this from either a dbf or another COM server, same length in any case.
cDataString = replicate('A', 50000)
nStrLen = LEN(cDataString)

*-- Fill array from cursor
aa = seconds()
CREATE CURSOR TempCursor (datastring M)
INSERT INTO TempCursor (datastring) VALUES (cDataString)

FOR nInc = 1 to nStrLen
taPassedArray[nInc] = SUBST(TempCursor.datastring, nInc, 1)
ENDFOR

bb = seconds()
MessageBox('SUBST(cursor.field) took '+allt(str(bb-aa,5,2))+' seconds')

*-- Fill array from variable
aa = seconds()
FOR nInc = 1 to nStrLen
taPassedArray[nInc] = SUBST(cDataString, nInc, 1)
ENDFOR

bb = seconds()
MessageBox('SUBST(variable) took '+allt(str(bb-aa,5,2))+' seconds')

ENDPROC
Next
Reply
Map
View

Click here to load this message in the networking platform