Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Interesting string behavior
Message
From
20/07/1999 05:04:46
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
19/07/1999 17:37:03
Gary Foster
Pointsource Consulting LLC
Chanhassen, Minnesota, United States
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00243326
Message ID:
00243470
Views:
25
>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
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform