[Pharo-project] About a object life
Folks: I wish know how old a object is. Any have code for this ? Thanks in advance Edgar
On Sun, Nov 4, 2012 at 2:45 PM, Max Leske <maxleske@gmail.com> wrote:
Only for new objects? If so, you could add an instance variable to Object and store a timestamp.
Well, kind of ;) Because if you do that, your image will crash. This is because the VM directly accesses (by offset) certain instVars of certain classes. For example, it knows that the MethodDictionary of a class is at the offset 2. So, if you add an instVar to Object all these offsets will be shifted, and VM will be accessing incorrect places, and therefore, a crash :)
On 03.11.2012, at 15:26, Edgar J. De Cleene <edgardec2005@gmail.com> wrote:
Folks:
I wish know how old a object is.
Any have code for this ?
Thanks in advance
Edgar
-- Mariano http://marianopeck.wordpress.com
ups :) On 04.11.2012, at 15:04, Mariano Martinez Peck <marianopeck@gmail.com> wrote:
On Sun, Nov 4, 2012 at 2:45 PM, Max Leske <maxleske@gmail.com> wrote: Only for new objects? If so, you could add an instance variable to Object and store a timestamp.
Well, kind of ;) Because if you do that, your image will crash. This is because the VM directly accesses (by offset) certain instVars of certain classes. For example, it knows that the MethodDictionary of a class is at the offset 2. So, if you add an instVar to Object all these offsets will be shifted, and VM will be accessing incorrect places, and therefore, a crash :)
On 03.11.2012, at 15:26, Edgar J. De Cleene <edgardec2005@gmail.com> wrote:
Folks:
I wish know how old a object is.
Any have code for this ?
Thanks in advance
Edgar
-- Mariano http://marianopeck.wordpress.com
Hi Edgar-- Do you really want to know how old an object is, or just whether it's older than some other object? If you don't care about degrading the identity hash distribution, you could steal a few bits from the object header for a counter. -C -- Craig Latta www.netjam.org/resume +31 6 2757 7177 + 1 510 396 5727
On 11/4/12 4:33 PM, "Craig Latta" <craig@netjam.org> wrote:
Hi Edgar--
Do you really want to know how old an object is, or just whether it's older than some other object? If you don't care about degrading the identity hash distribution, you could steal a few bits from the object header for a counter.
Craig: Like to know how old an object is. As my reply to Hans-Martin, guess this is not possible in current Pharo/Squeak. Nice to read you ! Edgar
participants (4)
-
Craig Latta -
Edgar J. De Cleene -
Mariano Martinez Peck -
Max Leske