Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Interesting string behavior
Message
From
20/07/1999 14:04:54
Gary Foster
Pointsource Consulting LLC
Chanhassen, Minnesota, United States
 
 
To
20/07/1999 05:04:46
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00243326
Message ID:
00243679
Views:
21
>>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
>Gary,
>Not much surprising. I tried to tell this before :) Memo files are kind of file streams. Also try this :
>
start = seconds()
>FOR ix = 1 to 10 && Do 10 times
>  CREATE CURSOR TempCursor (datastring M)
>  INSERT INTO TempCursor (datastring) VALUES (cDataString)
>  *-- Fill array from cursor
>
>  FOR nInc = 1 to nStrLen
>    taPassedArray[nInc] = SUBST(TempCursor.datastring, nInc, 1)
>  ENDFOR
>ENDFOR
>MESSAGEBOX('SUBST(cursor.field) took '+allt(str(seconds()-start,8,4))+' seconds')
>
>*-- Fill array from cursor
>start = seconds()
>FOR ix = 1 to 10 && Do 10 times
>  lcTempFile = "X"+sys(2015)+".Tmp"
>  handle = fcreate(lcTempFile)
>  =fwrite(handle,cDataString,nStrLen)
>  =fseek(handle,0,0)
>  FOR nInc = 1 to nStrLen
>    taPassedArray[nInc] = fread(handle,1)
>  ENDFOR
>  =fclose(handle)
>  ERASE (lcTempFile)
>ENDFOR
>MESSAGEBOX('Lowlevel took '+allt(str(seconds()-start,8,4))+' seconds')
A C routine (FLL) would be faster. ie: a 3Mb text file parsed distinct words, sorted and placed a cursor in fox takes under 3 secs. on a machine where above routines finish at about 5-6 secs.
>Cetin

It seems odd to me that there would be such a difference between working with memory variable and a file type of operation, whether cursor or low level. I just assumed that a variable would be faster than anything else. Thanks for the info, I tested it and low level won as you said. On another note, the reason I am doing this is that the C++ programmers on staff here seem unable to deal with any kind of BSTR's when DBCS rears its head. They tell me that if they try to write a DLL that deals with BSTR's, it will not work. Of course C++ can be made to handle DBCS, but they didn't want to deal with it.

Gary
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform