variables contain a reference to an object...?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
SAbboushi
Posts: 252
Joined: 08 Dec 2014, 22:13

variables contain a reference to an object...?

16 Jul 2018, 00:42




When I examine the memory address for a variable that contains a string or number, I can see the string or number starting at the variable's memory address (e.g. x:="abc"; I find "abc" in memory beginning at &x)

I understand the phrase "a reference to the object" to mean that instead of the object being stored at address &object, what is stored at &object is the address (i.e. a pointer) of where the object is stored. This seems to me in alignment with "&MyVar retrieves the address of MyVar's contents in memory"

But when I examine the memory at &object, I don't believe I'm finding an address; instead, I see a sequence of bytes that are identical for (what appears to be) all/any objects that I examine (e.g. &object1, &object2...).

And since ObjAddRef/ObjRelease use &object, that suggests to me that the object is stored at &object.

So I'm wondering whether a variable e.g. "object1" does in fact contain the address of where the object is stored, but &object is the address of where the object is stored and NOT the address of where object1's value is stored (the value being the address to where object 1 is stored)?

SUMMARY:
When you assign an object to a variable, as in myObj := {}, what you store is not the object itself, but a reference to the object
I understand this to mean:

Code: Select all

                        ADDRESS WHERE
VARIABLE NAME           VALUE IS STORED         VALUE
-------------------     --------------------    ---------------------------------------------------------
myObj                   &myObj                  address of where object is actually stored
&MyVar retrieves the address of MyVar's contents in memory
Then wouldn't this mean that the contents of myObj would be an address to the object?

Hoping someone will be kind enough to clarify for me.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: variables contain a reference to an object...?

16 Jul 2018, 03:28

Then wouldn't this mean that the contents of myObj would be an address to the object?
Yes, but it doesn't really matter, since the only documented use (that I can recall right now) of the return from &myObj doesn't really require it to be an actual address, that could change to some other identifier, eg, 1, 2, .... I guess that is unlikely though.
when I examine the memory at &object, I don't believe I'm finding an address
Why? Why do you have any expectations on what numget(&myObj) will return? It is not documented.
I see a sequence of bytes that are identical for (what appears to be) all/any objects that I examine (e.g. &object1, &object2...).
So maybe all Object()s have this incommon, or not ;)

Code: Select all

; sci-fi.
varsetcapacity x, 3737, 0
numput numget(&[]), x
(y:=object(&x))[1] := 123
msgbox isobject(y) "`n" type(y)  "`n" y.1 ; 1 Object 123, on a097
If you want to examine &obj, you need to look at the implementation, and you cannot rely on it not changing. There was an example of such (useless) explorations here, see the spoiler.

Cheers.
SAbboushi
Posts: 252
Joined: 08 Dec 2014, 22:13

Re: variables contain a reference to an object...?

17 Jul 2018, 15:08

Thanks Helgef for your response. It's given me a lot to absorb -- sent me deeper into the rabbit hole for 2 days! Still absorbing.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], mikeyww and 211 guests