What's the difference: Object.Length() vs. NumGet(&Object + 4*A_PtrSize) Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
magicinmath
Posts: 162
Joined: 12 Apr 2017, 23:03

What's the difference: Object.Length() vs. NumGet(&Object + 4*A_PtrSize)

19 May 2017, 19:58

Is one better than the other?

Is there a difference?
Guest

Re: What's the difference: Object.Length() vs. NumGet(&Object + 4*A_PtrSize)

19 May 2017, 20:36

What's the difference: Object.Length() vs. NumGet(&Object + 4*A_PtrSize)
Basically: Use the first one. And never use the second one.
https://autohotkey.com/boards/viewtopic ... 578#p21578
magicinmath
Posts: 162
Joined: 12 Apr 2017, 23:03

Re: What's the difference: Object.Length() vs. NumGet(&Object + 4*A_PtrSize)

19 May 2017, 20:56

Guest wrote:
What's the difference: Object.Length() vs. NumGet(&Object + 4*A_PtrSize)
Basically: Use the first one. And never use the second one.
https://autohotkey.com/boards/viewtopic ... 578#p21578
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?

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
More realistically I see the concern as:

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.
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: What's the difference: Object.Length() vs. NumGet(&Object + 4*A_PtrSize)  Topic is solved

19 May 2017, 21:13

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.'

Code: Select all

obj := []
obj["-1"] := ""
obj["1"] := ""
obj["a"] := ""

MsgBox % ""
.	obj.Length() "`n"
.	obj.SetCapacity(0)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: wilkster and 319 guests