General information
Title:
Interesting string behavior
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
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only