Jump to content

Max Variable Length


SmOke_N
 Share

Recommended Posts

  • Moderators

What is the Max Variable Length allowed?

I have found it to be 64 characters before an error is thrown, is this correct?

The help file says 64 dimensions for an Array under the variable but no mention of max character usage for the variable itself. And found nothing with Variable+Length here.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I am not positive, but I seem to remember it being some where in the range of 32767. That I cannot back up with the helpfile. I know a variable can hold many more than 62 characters. I have had a variable with darn near 500-1000 characters (If my estimations are correct).

My take,

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Perhaps a way of testing?

Global $Variable = "A"
Global $VariableAdd = "A"
While 1
    $Variable = $Variable & $VariableAdd
    If @Sec = 59 Then MsgBox(0, "Current Count", "Your variables current character count is " & StringLen($Variable))
WEnd
Func OnAutoItExit()
    MsgBox(0, "Exit", "AutoIt closed out with a variable count of " & StringLen($Variable))
EndFunc

Just a quick thought.

AutoIt Smith

Edited by AutoIt Smith
Link to comment
Share on other sites

What is the Max Variable Length allowed?

AutoIt Smith's code appears to test the length of a variable's content. The theoretical maximum according to the help file is 2,147,483,647 characters (from the FAQ). If you mean 'how long can a variable's identifer be' however, then there doesn't appear to be a theoretical maximum.

The script below attempts to set $AA, then $AAAA, then $AAAAAAAA, etc. (it doubles the length of the variable name each time). This script will hog CPU and memory rather quickly so be careful if you do run it.

Local $VarName = 'A'
Do
    $VarName &= $VarName
    If Not Assign($VarName, 'Test', 1) Then ExitLoop
    ToolTip(StringLen($VarName))
Until Eval($VarName) <> 'Test'
MsgBox(0, '', 'Could not set a variable with a name ' & StringLen($VarName) & ' characters long.')
Link to comment
Share on other sites

LxP, that's not an accurate test. Assign() is notorious for not having much error checking as compared to using the language syntax itself.

When I read this, however, I ask the question, why do you care? Even if there was a limit at 64 characters, it should never be an issue. Identifiers that long are more difficult to read than short, descriptive identifiers. I don't know if there is a limit on the length or not from a technical perspective but from a code readability perspective, identifiers shouldn't be very long at all.

Link to comment
Share on other sites

LxP, that's not an accurate test. Assign() is notorious for not having much error checking as compared to using the language syntax itself.

When I read this, however, I ask the question, why do you care? Even if there was a limit at 64 characters, it should never be an issue. Identifiers that long are more difficult to read than short, descriptive identifiers. I don't know if there is a limit on the length or not from a technical perspective but from a code readability perspective, identifiers shouldn't be very long at all.

unless you're intentionally trying to reduce readability, in which case i'd think it a valid question... :P
Link to comment
Share on other sites

  • Moderators

When I read this, however, I ask the question, why do you care? Even if there was a limit at 64 characters, it should never be an issue.

Never said it was an issue, it was more for plain curiousity. I can't seem to replicate it at the moment either, so it must have been my mistake :P

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

LxP, that's not an accurate test. Assign() is notorious for not...

Then perhaps this test will do:
HotKeySet("{PAUSE}", "Terminate")

$tmp = ""
ClipPut("")
Sleep(200)

For $i = 1 To 4090
    $tmp = $tmp & "1"
Next

ClipPut("$" & $tmp & "=''" & @LF & 'MsgBox(0,"",' & StringLen($tmp) & ')')

FileWrite(FileOpen("c:\temp\temp.au3", 2), ClipGet())
FileClose("c:\temp\temp.au3")
Run(@AutoItExe & " c:\temp\temp.au3")

Exit
Func Terminate()
    Exit
EndFunc
Just manually increment the "4090" in the For/Next loop above.

Edit2: See here for an explanation of the code layout shown above and the rationale for using ClipPut/ClipGet.

It seems to be more related to:

"Maximum length of a single script line: 4,095"

To quote SmOke_N, "...it was more for plain curiousity".

Edit1: Replaced @CRLF with just @LF

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

  • Moderators

It seems to be more related to:

"Maximum length of a single script line: 4,095"

@HWP - That may have been the issue now that I think about it... :lmao:

@cameronsdad - whatever do you mean :P

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Then perhaps this test will do

damn that code is so bugged.

most if it is obsolete and other things wont even do what you want.

to be honest i wouldnt even expect code like this from someone who got autoit a day ago.

this is probly what you ment:

HotKeySet("{PAUSE}", "Terminate")

dim $s_tmp = "", $h_andle

For $i = 1 To 4092
    $s_tmp &= "a"
    
    $h_andle = FileOpen("c:\temp\temp.au3", 2)
    FileWrite($h_andle, '$' & $s_tmp & '=0')
    FileClose($h_andle)
    
    ConsoleWrite($i & @LF)
    
    RunWait(@AutoItExe & " c:\temp\temp.au3")
Next

Func Terminate()
    Exit
EndFunc
Edited by w0uter

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Link to comment
Share on other sites

unless you're intentionally trying to reduce readability, in which case i'd think it a valid question... :P

If you're referring to obfuscating the code by making extraordinarily long variable names, I can shorten then with a simple regular expression.
Link to comment
Share on other sites

LxP, that's not an accurate test. Assign() is notorious for not having much error checking as compared to using the language syntax itself.

I attempted to counter this via the Eval() call on the Until line. The script continued to run past a length of 16,000,000 on my system which suggested to me at the time that this should be adequate.
Link to comment
Share on other sites

...this is probly what you ment:

Nope. I meant what I posted. I did not want to creep up on the answer by starting at 1 and running the temp.au3 script 4000+ times. I thought that I knew the number to test. I tested 4090 and 4095 and I had my answer... the "4095 limit" is the issue. You are correct that such a code layout would not be the best for a large range of numbers.

I understand that the ClipPut/ClipGet looks weird, but understand that this was recycled code that I had used to test problems with the clipboard functions after large data swaps. I just added the loop and tweaked the ClipPut line. I thought it was a rather clever recycle... but thanks for your rewrite, I did study it.

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Ditto my comment about Assign() only replace "Assign" with "Eval".

But if an Assign() fails then surely Eval() won't return a specific value like 'Test'...? I don't think I understand what you're saying then.

Edit: Yes, the Eval() may of course possibly fail even if the Assign() within that iteration doesn't, however I don't see how the While loop can reiterate if the Assign() fails because the Eval() will also fail without doubt. Can you please further explain what you mean?

Edited by LxP
Link to comment
Share on other sites

But if an Assign() fails then surely Eval() won't return a specific value like 'Test'...? I don't think I understand what you're saying then.

Edit: Yes, the Eval() may of course possibly fail even if the Assign() within that iteration doesn't, however I don't see how the While loop can reiterate if the Assign() fails because the Eval() will also fail without doubt. Can you please further explain what you mean?

Speaking in a hypothetical sense, there are two places checking can be done for the length of a variable name. The first would be done during the pre-run syntax checking. The second would be in the variable-related code which handles the creation/storage of variables. If the check for variable length was performed in the first location, Assign() and Eval() would both bypass this check an essentially invoke undefined behavior. If the check were in the second location, then Assign() would obey the same rules as a statically declared variable and thus both Assign() and Eval() would fail.

I don't know if there is a limit to the length of a variable name. If there is a check, I would place a large sum of money in it being in the first location and not the second location. With all that being said, the chances of Assign() and Eval() doing the right thing are next to none.

This is of course all speculation on my part. However, since I wrote Assign(), I know that it's a maintenance liability with regards to keeping it's behavior consistent with the more traditional method of assigning variables so with that knowledge in mind, Assign() is not suitable for this test.

Link to comment
Share on other sites

Thanks Valik; I better understand what you mean now.

You seem to suggest that (as an example) a request to Assign() or Eval() a variable whose name consists of 500 Xs may in fact create/operate on a variable whose name consists of 250 Xs (or some other arbitrary number less than 500). Hence an Eval() following an Assign() does not guarantee success as they both may be checking a different variable (although both would check the same different variable).

This can be likened to labels in DOS batch files, where only the first 8 characters are used and therefore Label1234 is equivalent to Label1235.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...