Internal representation of objects

前端 未结 2 655
[愿得一人]
[愿得一人] 2021-01-21 02:46

So all this time I thought that when you do something like ObjectA.field1, ObjectA is just like any value on the stack and you basically access its fields. Now I was going throu

2条回答
  •  面向向阳花
    2021-01-21 03:32

    To get the field1 of some ObjectA of some ClassAthe computer has to have the address of the memory zone containing ObjectA, it knows (statically) the offset (in bytes) for field1 (of ClassA) so it can retrieve the field1 by adding that offset to the adress of ObjectA.

提交回复
热议问题