Sign in to follow this  
Followers 0
Chu

Question about array syntax and Dim

6 posts in this topic

#1 ·  Posted (edited)

Hello all. I have a function that looks like this:

Func ePC($coords)
    ...
EndFunc

It takes in a $something[4] and spit outs an integer.

Elsewhere in my program I have a $something[5][4]. I was searching the forums, and apparently there is no way to do something like ePC($something[5][]). If this is wrong please correct me! I really can't believe in three versions noone has added this feature . . .

Anyways, as a workaround, instead I have this:

Dim $tmp_0[5]
For $i = 0 to 4 Step 1
    Dim $tmp_1[4] = [$watch_2[$i][0], $watch_2[$i][1], $watch_2[$i][2], $watch_2[$i][3]]
    $tmp_0[$i] = ePC($tmp_1)
Next

My question is about what "Dim" actually does. This is probably going to be running in a service and this code is going to be called hundreds of thousands of times, maybe millions. My question is if AutoIt either has a "delete" keyword so I can explicitly free that space, or if the garbage collector is smart enough to release that space on its own.

Edited by Chu

Share this post


Link to post
Share on other sites



There's an ArrayDelete() function and Dim declares a variable for use.

Where is ArrayDelete() exactly? I'm having trouble finding it in the official docs.

My question is what does "declare" mean exactly. I assume it's allocating space on the heap dynamically at runtime which means it just sits there until something explicitly kills it.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Declaring in a nutshell for a arrays means defining the name of the variable, and the elements the array has. You decalre it in one of 3 scopes, just like normal variables- Global, Dim (Local if variable not global), Local.

Check this out for declaring.

Dim $array[10]; Array with 10 elements.

$array[0] = "Something"

MsgBox (0, "", $array[0])

You can find _ArrayDelete() in the UDF section of the helpfile, under Array Management.

Cheers,

Brett

Edited by BrettF

Share this post


Link to post
Share on other sites

Hello all. I have a function that looks like this:

Func ePC($coords)
    ...
EndFunc

It takes in a $something[4] and spit outs an integer.

Elsewhere in my program I have a $something[5][4]. I was searching the forums, and apparently there is no way to do something like ePC($something[5][]). If this is wrong please correct me! I really can't believe in three versions noone has added this feature . . .

Anyways, as a workaround, instead I have this:

Dim $tmp_0[5]
For $i = 0 to 4 Step 1
    Dim $tmp_1[4] = [$watch_2[$i][0], $watch_2[$i][1], $watch_2[$i][2], $watch_2[$i][3]]
    $tmp_0[$i] = ePC($tmp_1)
Next

My question is about what "Dim" actually does. This is probably going to be running in a service and this code is going to be called hundreds of thousands of times, maybe millions. My question is if AutoIt either has a "delete" keyword so I can explicitly free that space, or if the garbage collector is smart enough to release that space on its own.

The help file under index tab find Local, It has some good information - find Array = 0 in Local 's documentation.

Also ReDim backs up the info under Local in help file.

So each time Dim $tmp_1[4] is run, the previous values in the array $tmp_1 are erased because of the Dim statement.

And your work around is the way to go. I know nothing in AutoIt which allows anything like ePC($something[4][0 to 3]) for a 5x4 array

What is possible is :-

ePC($something) - pass entire array: or

ePC($something[4][0], $something[4][1], $something[4][2], $something[4][3]) - Passing 4 parameters or more.

Here is another possibility,

Local $tmp_0[4]

For $i = 0 To 3

$tmp_0[$i] = ePC($watch_2[$i][0], $watch_2[$i][1], $watch_2[$i][2], $watch_2[$i][3])

Next

The ePC() function would need to modified.

Func ePC($coord1, $coord2, $coord3, $coord4)

Hope this helps.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Thanks a lot for the help.

I really can't modify the function though, it's used mostly in it's written form in other functions and I don't think AutoIt supports overloading (does it?).

Edited by Chu

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