adding instance variables (data) to the Object class

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

adding instance variables (data) to the Object class

Pharo Smalltalk Users mailing list
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)?

Thanks! pf

Reply | Threaded
Open this post in threaded view
|

Re: adding instance variables (data) to the Object class

Marcus Denker-4


On 6 Sep 2018, at 23:35, Petr Fischer via Pharo-users <[hidden email]> wrote:


From: Petr Fischer <[hidden email]>
Subject: adding instance variables (data) to the Object class
Date: 6 September 2018 at 23:35:26 CEST


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
Reply | Threaded
Open this post in threaded view
|

Re: adding instance variables (data) to the Object class

Denis Kudriashov
Talents with statefull traits will help you

пт, 7 сент. 2018 г., 9:08 Marcus Denker <[hidden email]>:


On 6 Sep 2018, at 23:35, Petr Fischer via Pharo-users <[hidden email]> wrote:


From: Petr Fischer <[hidden email]>
Subject: adding instance variables (data) to the Object class
Date: 6 September 2018 at 23:35:26 CEST


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
Reply | Threaded
Open this post in threaded view
|

Re: adding instance variables (data) to the Object class

Pharo Smalltalk Users mailing list
I see... will test them, thanks! pf


> Talents with statefull traits will help you
>
> пт, 7 сент. 2018 г., 9:08 Marcus Denker <[hidden email]>:
>
> >
> >
> > On 6 Sep 2018, at 23:35, Petr Fischer via Pharo-users <
> > [hidden email]> wrote:
> >
> >
> > *From: *Petr Fischer <[hidden email]>
> > *Subject: **adding instance variables (data) to the Object class*
> > *Date: *6 September 2018 at 23:35:26 CEST
> > *To: *[hidden email]
> >
> >
> > 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
> >

Reply | Threaded
Open this post in threaded view
|

Re: adding instance variables (data) to the Object class

Pharo Smalltalk Users mailing list
In reply to this post by Denis Kudriashov
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 <[hidden email]>:
>
> >
> >
> > On 6 Sep 2018, at 23:35, Petr Fischer via Pharo-users <
> > [hidden email]> wrote:
> >
> >
> > *From: *Petr Fischer <[hidden email]>
> > *Subject: **adding instance variables (data) to the Object class*
> > *Date: *6 September 2018 at 23:35:26 CEST
> > *To: *[hidden email]
> >
> >
> > 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
> >

Reply | Threaded
Open this post in threaded view
|

Re: adding instance variables (data) to the Object class

Sean P. DeNigris
Administrator
Pharo Smalltalk Users mailing list wrote
> Or... what do you mean by "talents"?

IIUC a talent is behavior like a trait, but that can be dynamically added
and removed from anObject instead of being permanently bound to the class



-----
Cheers,
Sean
--
Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html

Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: adding instance variables (data) to the Object class

Richard O'Keefe
In reply to this post by Pharo Smalltalk Users mailing list
I am having a little trouble understanding how adding instance
variables to Object is supposed to work.  Where would an immediate
object like a SmallInteger *put* such variables?  What does it even
*mean* for 0 and 1 to have instance variables?  Do you really want
to give an extra word of storage to *every* object in your system,
or to just some, but potentially of any kind?

The usual technique is to use something like a WeakIdentityKeyDictionary.

On Mon, 14 Jan 2019 at 13:54, Petr Fischer via Pharo-users <[hidden email]> wrote:
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 <[hidden email]>:
>
> >
> >
> > On 6 Sep 2018, at 23:35, Petr Fischer via Pharo-users <
> > [hidden email]> wrote:
> >
> >
> > *From: *Petr Fischer <[hidden email]>
> > *Subject: **adding instance variables (data) to the Object class*
> > *Date: *6 September 2018 at 23:35:26 CEST
> > *To: *[hidden email]
> >
> >
> > 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
> >

Reply | Threaded
Open this post in threaded view
|

Re: adding instance variables (data) to the Object class

Pharo Smalltalk Users mailing list
Yes, due to the object layouts and strong connection of Object with VM, my idea can not be done that easily.

I want to add some information (instance variables like OID [object id]) to some objects of any kind (some objects = persistent objects).

I can do it with map (idenity as key, OID + other info as value), but I was afraid that the map would tend to be enormous.
Now (with all your feedback) I am inclined to think that this (map/dictionary) will be the only way.

Also - on some systems (like Gemstone), there is "dynamic instance variables" (just key/value pairs) and you can add some information to any object instance you want. I like this, but not possible in Pharo, right?

Thanks! pf


> I am having a little trouble understanding how adding instance
> variables to Object is supposed to work.  Where would an immediate
> object like a SmallInteger *put* such variables?  What does it even
> *mean* for 0 and 1 to have instance variables?  Do you really want
> to give an extra word of storage to *every* object in your system,
> or to just some, but potentially of any kind?
>
> The usual technique is to use something like a WeakIdentityKeyDictionary.
>
> On Mon, 14 Jan 2019 at 13:54, Petr Fischer via Pharo-users <
> [hidden email]> wrote:
>
> > 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 <[hidden email]>:
> > >
> > > >
> > > >
> > > > On 6 Sep 2018, at 23:35, Petr Fischer via Pharo-users <
> > > > [hidden email]> wrote:
> > > >
> > > >
> > > > *From: *Petr Fischer <[hidden email]>
> > > > *Subject: **adding instance variables (data) to the Object class*
> > > > *Date: *6 September 2018 at 23:35:26 CEST
> > > > *To: *[hidden email]
> > > >
> > > >
> > > > 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
> > > >
> >
> >

Reply | Threaded
Open this post in threaded view
|

Re: adding instance variables (data) to the Object class

jgfoster


On Jan 16, 2019, at 6:28 AM, Petr Fischer via Pharo-users <[hidden email]> wrote:


From: Petr Fischer <[hidden email]>
Subject: Re: [Pharo-users] adding instance variables (data) to the Object class
Date: January 16, 2019 at 6:28:44 AM PST


Yes, due to the object layouts and strong connection of Object with VM, my idea can not be done that easily.

I want to add some information (instance variables like OID [object id]) to some objects of any kind (some objects = persistent objects).

I can do it with map (idenity as key, OID + other info as value), but I was afraid that the map would tend to be enormous.
Now (with all your feedback) I am inclined to think that this (map/dictionary) will be the only way.

Also - on some systems (like Gemstone), there is "dynamic instance variables" (just key/value pairs) and you can add some information to any object instance you want. I like this, but not possible in Pharo, right?

While GemStone allows dynamic instance variables on most objects (to support Ruby), it is not allowed on “special” objects like SmallInteger instances that are encoded completely in the OOP.


Thanks! pf


I am having a little trouble understanding how adding instance
variables to Object is supposed to work.  Where would an immediate
object like a SmallInteger *put* such variables?  What does it even
*mean* for 0 and 1 to have instance variables?  Do you really want
to give an extra word of storage to *every* object in your system,
or to just some, but potentially of any kind?

The usual technique is to use something like a WeakIdentityKeyDictionary.

On Mon, 14 Jan 2019 at 13:54, Petr Fischer via Pharo-users <
[hidden email]> wrote:

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 <[hidden email]>:



On 6 Sep 2018, at 23:35, Petr Fischer via Pharo-users <
[hidden email]> wrote:


*From: *Petr Fischer <[hidden email]>
*Subject: **adding instance variables (data) to the Object class*
*Date: *6 September 2018 at 23:35:26 CEST
*To: *[hidden email]


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








Reply | Threaded
Open this post in threaded view
|

Re: adding instance variables (data) to the Object class

Pharo Smalltalk Users mailing list
In reply to this post by Pharo Smalltalk Users mailing list
Petr,

Since you seem to want to add this (these) extra instance variable(s) in
the context of some kind of persistence (objects being retrieved/created
from/to some kind of database), perhaps subclassing all your objects
from a PersistentObject class (that inherits from Object) would be the
simplest solution.



Reply | Threaded
Open this post in threaded view
|

Re: adding instance variables (data) to the Object class

Stephan Eggermont-3
In reply to this post by Pharo Smalltalk Users mailing list
Petr Fischer via Pharo-users
<[hidden email]> wrote:
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)?

You might want to take a look at the documentation of Magma.
http://wiki.squeak.org/squeak/2665

Stephan