Re: [Pharo-users] adding instance variables (data) to the Object class
On 6 Sep 2018, at 23:35, Petr Fischer via Pharo-users <pharo-users@lists.pharo.org> wrote:
From: Petr Fischer <petr.fischer@me.com> Subject: adding instance variables (data) to the Object class Date: 6 September 2018 at 23:35:26 CEST To: pharo-users@lists.pharo.org
Hello! Weird question: why I can't add instance variables to the Object class (for example "oid" or something else)? Is it due to some internal (and different) VM "class layouts"?
Or - can I inject my own information to all existing objects (any class)?
Behavior is a subclass of Object, too. So that means that you would add a ivar to all the classes, but for the VM an object can only be a class that has three ivars, and those are accessed by offset. So if you add an ivar, you shift the offset â> problem. As for âI want to add object specific stateâ: it would be nice to add an easy to use (and efficient) mechanism to do it. Marcus
Talents with statefull traits will help you пÑ, 7 ÑенÑ. 2018 г., 9:08 Marcus Denker <marcus.denker@inria.fr>:
On 6 Sep 2018, at 23:35, Petr Fischer via Pharo-users < pharo-users@lists.pharo.org> wrote:
*From: *Petr Fischer <petr.fischer@me.com> *Subject: **adding instance variables (data) to the Object class* *Date: *6 September 2018 at 23:35:26 CEST *To: *pharo-users@lists.pharo.org
Hello! Weird question: why I can't add instance variables to the Object class (for example "oid" or something else)? Is it due to some internal (and different) VM "class layouts"?
Or - can I inject my own information to all existing objects (any class)?
Behavior is a subclass of Object, too. So that means that you would add a ivar to all the classes, but for the VM an object can only be a class that has three ivars, and those are accessed by offset. So if you add an ivar, you shift the offset â> problem.
As for âI want to add object specific stateâ: it would be nice to add an easy to use (and efficient) mechanism to do it.
Marcus
I see... will test them, thanks! pf
Talents with statefull traits will help you
пÑ, 7 ÑенÑ. 2018 г., 9:08 Marcus Denker <marcus.denker@inria.fr>:
On 6 Sep 2018, at 23:35, Petr Fischer via Pharo-users < pharo-users@lists.pharo.org> wrote:
*From: *Petr Fischer <petr.fischer@me.com> *Subject: **adding instance variables (data) to the Object class* *Date: *6 September 2018 at 23:35:26 CEST *To: *pharo-users@lists.pharo.org
Hello! Weird question: why I can't add instance variables to the Object class (for example "oid" or something else)? Is it due to some internal (and different) VM "class layouts"?
Or - can I inject my own information to all existing objects (any class)?
Behavior is a subclass of Object, too. So that means that you would add a ivar to all the classes, but for the VM an object can only be a class that has three ivars, and those are accessed by offset. So if you add an ivar, you shift the offset â> problem.
As for âI want to add object specific stateâ: it would be nice to add an easy to use (and efficient) mechanism to do it.
Marcus
It looks like I can't simply add statefull trait to the Object like this: ProtoObject subclass: #Object uses: TMyTrait instanceVariableNames: '' classVariableNames: 'DependentsFields' package: 'Kernel-Objects' After this, Pharo 7 VM goes to 100% of CPU usage, several GB of RAM usage and then crash. Or... what do you mean by "talents"? I found also this: https://github.com/tesonep/pharo-talents Thanks, pf
Talents with statefull traits will help you
пÑ, 7 ÑенÑ. 2018 г., 9:08 Marcus Denker <marcus.denker@inria.fr>:
On 6 Sep 2018, at 23:35, Petr Fischer via Pharo-users < pharo-users@lists.pharo.org> wrote:
*From: *Petr Fischer <petr.fischer@me.com> *Subject: **adding instance variables (data) to the Object class* *Date: *6 September 2018 at 23:35:26 CEST *To: *pharo-users@lists.pharo.org
Hello! Weird question: why I can't add instance variables to the Object class (for example "oid" or something else)? Is it due to some internal (and different) VM "class layouts"?
Or - can I inject my own information to all existing objects (any class)?
Behavior is a subclass of Object, too. So that means that you would add a ivar to all the classes, but for the VM an object can only be a class that has three ivars, and those are accessed by offset. So if you add an ivar, you shift the offset â> problem.
As for âI want to add object specific stateâ: it would be nice to add an easy to use (and efficient) mechanism to do it.
Marcus
participants (3)
-
Denis Kudriashov -
Marcus Denker -
Petr Fischer