Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Dynamically Sizing Arrays
Message
From
01/06/2001 05:32:15
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
31/05/2001 18:48:30
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00513486
Message ID:
00513629
Views:
20
>>>I have a situation where I need to add an unknown
>>>number of rows to an array. I think I have two
>>>options, 1) redimension the array for each new element
>>>that I need to add, or 2) concat everything to a string
>>>counting the elements as I go, then use something like
>>>WORDNUM() or ALINES() or some such, then redimensioning
>>>the array one time.
>>>
>>>My question is, efficiency wise, which would be the best
>>>solution?
>>>
>>>I'm running VFP 6, and I'm anticipating a maximum of
>>>maybe 50 rows.
>>>
>>>What say U?
>>>
>>> ...kt
>>
>>First is the solution :) Saying concat I assume you'd get char data.
>
>Good point. I do (now) have one numeric value that needs
>to be added to the array. This is pro'ly out of question.
>
>>
dimension myArray[1] && Initial declaration
>>....
>>* Add new element
>>dimension myArray[iif(type('myArray')='L',0,alen(myArray))+1]
>>myArray[alen(myArray)]=myVal
Cetin
>
>What kind of performance penalty is imposed by redimensioning
>the array each time?
>
> ...kt

Keith,
Saying 'assuming char' I only wanted to mean if you'd support logical too then sample code would need extra check :) Other than that it's OK (see checking if array has data set yet is only done by checking if first item type was logical)

In 'practice' I would say none. Array processing is much faster than rest and max array elems is 65000 making it nearly impossible to create a performance test. Creating say a cursor and inserting in it would be slower IMHO and would require some workaround if all elements in an array column are not same datatype.
Visit my web site www.foxyclasses.com There objxplorer sample uses this technique to collect 'all' form control obj.ref into array and it does it per call (I had reasons not to persist) when you click :
'List all','List collection','ExecAll','Zorder some labels','Zorder all labels'.
Cetin
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
Reply
Map
View

Click here to load this message in the networking platform