Is one better than the other?
Is there a difference?
What's the difference: Object.Length() vs. NumGet(&Object + 4*A_PtrSize) Topic is solved
-
- Posts: 162
- Joined: 12 Apr 2017, 23:03
Re: What's the difference: Object.Length() vs. NumGet(&Object + 4*A_PtrSize)
ObjCount() or ObjLength() or ObjLen()
https://autohotkey.com/boards/viewtopic.php?f=37&t=3950
https://autohotkey.com/boards/viewtopic.php?f=37&t=3950
Re: What's the difference: Object.Length() vs. NumGet(&Object + 4*A_PtrSize)
Basically: Use the first one. And never use the second one.What's the difference: Object.Length() vs. NumGet(&Object + 4*A_PtrSize)
https://autohotkey.com/boards/viewtopic ... 578#p21578
-
- Posts: 162
- Joined: 12 Apr 2017, 23:03
Re: What's the difference: Object.Length() vs. NumGet(&Object + 4*A_PtrSize)
This example demonstrates why I thought the second is better if I need the number of elements in an array and not just the max index?Guest wrote:Basically: Use the first one. And never use the second one.What's the difference: Object.Length() vs. NumGet(&Object + 4*A_PtrSize)
https://autohotkey.com/boards/viewtopic ... 578#p21578
Code: Select all
obj:=[]
obj[-1]:="4"
obj[1]:="1"
obj[a]:="2"
Var:=obj.Length() ; Returns 1
MsgBox, obj.Length(): %Var%
Var:=NumGet(&obj + 4*A_PtrSize) ; Returns 3
MsgBox, NumGet(&obj + 4*A_PtrSize): %Var%
ExitApp
Code: Select all
obj2:=[]
obj2[1]:=""
obj2[3]:=""
obj2[5]:=""
Var:=obj2.Length()
MsgBox, obj2.Length(): %Var% ;returns 5
Var:=NumGet(&obj2 + 4*A_PtrSize)
MsgBox, NumGet(&obj2 + 4*A_PtrSize): %Var% ;returns 3
ExitApp
Last edited by magicinmath on 19 May 2017, 21:16, edited 2 times in total.
Re: What's the difference: Object.Length() vs. NumGet(&Object + 4*A_PtrSize)
Personally, I do not use integer as keys.
https://autohotkey.com/docs/Objects.htm#Keys
https://autohotkey.com/docs/Objects.htm#Keys
Re: What's the difference: Object.Length() vs. NumGet(&Object + 4*A_PtrSize) Topic is solved
And, you have to see this one.
Length method
https://autohotkey.com/docs/objects/Obj ... ngth_v1121+
'Returns the length of a linear array beginning at position 1; that is, the highest positive integer key contained by the object, or 0 if there aren't any.'
Length method
https://autohotkey.com/docs/objects/Obj ... ngth_v1121+
'Returns the length of a linear array beginning at position 1; that is, the highest positive integer key contained by the object, or 0 if there aren't any.'
Code: Select all
obj := []
obj["-1"] := ""
obj["1"] := ""
obj["a"] := ""
MsgBox % ""
. obj.Length() "`n"
. obj.SetCapacity(0)
-
- Posts: 162
- Joined: 12 Apr 2017, 23:03
Who is online
Users browsing this forum: dunnerca, Google [Bot] and 163 guests