If I do SmallInteger alIInstances I get an empty array, and of course, with SmallInteger instanceCount I get zero.
Now, I can understand that from the VM point of view, but for the final user, this should be polymorphic. For example, for instanceCount, I would like to know all the "variable slots" that has a 1 in the last bit. Is this already possible? if true, which message? if not, should I hack in the vm and code a primitive that does this? And the same for allInstances, if I can inspect 5, I should be also to inspect SmallInteger allInstances, and SmallInteger allInstances first, etc.... thanks Mariano |
Mariano,
I see your point, but given the immediate object encoding tricks I'm not sure it's possible. Would the class methods #minVal and #maxVal be of any use to you? Bill ________________________________________ From: [hidden email] [[hidden email]] On Behalf Of Mariano Martinez Peck [[hidden email]] Sent: Sunday, November 21, 2010 4:41 PM To: Pharo Development Subject: [Pharo-project] is there an easy way to know the SmallInteger instances? If I do SmallInteger alIInstances I get an empty array, and of course, with SmallInteger instanceCount I get zero. Now, I can understand that from the VM point of view, but for the final user, this should be polymorphic. For example, for instanceCount, I would like to know all the "variable slots" that has a 1 in the last bit. Is this already possible? if true, which message? if not, should I hack in the vm and code a primitive that does this? And the same for allInstances, if I can inspect 5, I should be also to inspect SmallInteger allInstances, and SmallInteger allInstances first, etc.... thanks Mariano |
On Sun, Nov 21, 2010 at 11:55 PM, Schwab,Wilhelm K <[hidden email]> wrote: Mariano, :( It's a pity. Because most users should not be aware of this. This should be completly transparent for the developer. Would the class methods #minVal and #maxVal be of any use to you? No :( Maybe it is better in this way: I want to know how many instances/temp var have a SmallInetger. This means, how many slots/words have a 1 in the last bit. This is what I understand by "Smallinteger instances".
|
On Sun, Nov 21, 2010 at 2:59 PM, Mariano Martinez Peck <[hidden email]> wrote:
That's the number of references to SmallInteger. If all those slots contain references to 0 then they're still referring to a single object. The number of instances of SmallInteger is SmallInteger maxVal - SmallInteger minVal + 1, period. But they're virtual objects so they don't take any space; only their references take space. (IMO)
So you could implement SmallInteger class>>instanceCount ^self maxVal - self minVal + 1 SmallInteger class>>allInstances
^self minVal to: self maxVal you could implement the following but it's of academic interest only; it'll take a long time on a 64-bit implementation ;) If you add this then you have to guard against it being invoked because shure as s**t someone will wonder why the system isn't doing anything when they ask some apparently reasonable question about instance counts...
SmallInteger class>>allInstancesDo: aBlock self minVal to: self maxVal do: aBlock best Eliot
|
On Mon, Nov 22, 2010 at 12:10 AM, Eliot Miranda <[hidden email]> wrote:
ok...and how can I know this then? ;)
isn't that all the MAX possible instances??? If in my whole image, I never use the number 42, why would you count it?
Ok, at least we agree it cannot be zero. At least it is not clear from a normal developer that doesnt know anything about the VM.
|
In reply to this post by Eliot Miranda-2
But by iterating over all small integers, are you not "instantiating" ones that were not in use? Dr. Heisenberg will get a good grin out this one :)
________________________________________ From: [hidden email] [[hidden email]] On Behalf Of Eliot Miranda [[hidden email]] Sent: Sunday, November 21, 2010 6:10 PM To: [hidden email] Subject: Re: [Pharo-project] is there an easy way to know the SmallInteger instances? So you could implement SmallInteger class>>instanceCount ^self maxVal - self minVal + 1 SmallInteger class>>allInstances ^self minVal to: self maxVal you could implement the following but it's of academic interest only; it'll take a long time on a 64-bit implementation ;) If you add this then you have to guard against it being invoked because shure as s**t someone will wonder why the system isn't doing anything when they ask some apparently reasonable question about instance counts... SmallInteger class>>allInstancesDo: aBlock self minVal to: self maxVal do: aBlock best Eliot |
In reply to this post by Mariano Martinez Peck
Mariano,
Your post has made think. . . for the final user this would put this method farther from OO as possible, wouldn't it? |
On Tue, Nov 23, 2010 at 8:18 PM, <[hidden email]> wrote: Mariano, which method and why ? ;) |
In reply to this post by Mariano Martinez Peck
Mariano, SmallIntegers don't really exist as objects. The compiler/vm only make you think they exist. In fact they are encoded in the object pointer. Perhaps you knew this already. As to the other question, how many variables hold a SmallInteger, you cannot really calculate that for temp vars, although you could get a good stab at it if you are determined. For instance variables, you collect all objects in the image in a collection, then for each element you enumerate from 1 to the number of named instvars using x class instSize and instVarAt: and also the indexed inst vars using basicSize and basicAt: and each time you test if the class is SmallInteger and if so you increment a counter Does that help? Cheers, Peter On Mon, 22 Nov 2010 00:48:03 +0100, Mariano Martinez Peck <[hidden email]> wrote:
-- Peter van Rooijen Nijlring 83 5152 VJ Drunen m: 06-2854 2048 |
Free forum by Nabble | Edit this page |