Sign in to follow this  
Followers 0
Arrrghmatey

Vectors?

7 posts in this topic

I need to read a large amount of information from a file and place it in an array. (I'll then use it for coordinates) However, since I do not know the amount of items I will have, I'd like to place it in a vector. This possible/feasible in Autoit?

Share this post


Link to post
Share on other sites



If I have well over a hundred items that need to be placed in the array, would this technique use excessive system resources/memory or be slow? I'm really new to this, but the speed of this is important. I don't want it to lag more than a second or two....

Share this post


Link to post
Share on other sites

(aint vector's slow btw ?)

<{POST_SNAPBACK}>

Yes, you are right, but they are faster than redimming it every single time you add a new element. As far as I understand, a vector is just a data structure wrapped around an array. Usually when the array is full, a new array is created that is twice the size of the original, so it is not redimmed constantly.

I think I solved my problem by creating a quick and dirty addItem function:

$Array[0] = $Array[0] + 1
    If $array[0] > UBound($array) Then 
        ReDim $array[$array[0] * 2]
    $array[$array[0]] = $newValue
    EndIf

I don't need to delete any items, so I don't really need a full blown vector. Does this look right?

Share this post


Link to post
Share on other sites

Ok, I just want to say that I am a complete idiot. I just found a function that does EXACTLY what I wanted. IniReadSection does it, and ini files look MUCH better than my config format. I guess it pays to read ALL of the documentation first. I am still learning so I didn't know what an ini file was until now. I feel silly :)

Share this post


Link to post
Share on other sites

What I tend to do is ReDim with a fairly large number each time.

Dim $nLast = -1 ; Last element that is active
Dim $vArray[99] ; Set array to 99 element

...
; Add new element ($new_data) to array
$nLast += 1
if UBound($vArray) -1 < $nLast Then
     ReDim $vArray[$nLast + 99]
Endif
$vArray[$nLast] = $new_data
...
; Finished loading, redim to proper size
ReDim $vArray[$nLast+1]

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0