<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.1.2" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Understanding Fixnums</title>
	<link>http://www.rubyfleebie.com/understanding-fixnums/</link>
	<description>Because programming should be fun</description>
	<pubDate>Sat, 22 Nov 2008 03:44:27 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.1.2</generator>

	<item>
		<title>By: Arne</title>
		<link>http://www.rubyfleebie.com/understanding-fixnums/#comment-48</link>
		<author>Arne</author>
		<pubDate>Mon, 02 Apr 2007 10:07:00 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/understanding-fixnums/#comment-48</guid>
					<description>Hello,

This doesn't appear to me to be entirely correct, Fixnum objects are unique and immutable, so every '5' in the system is the same Fixnum instance with the same oid. However, variables can still contain references to this instance, just like every ruby variable contains just a reference to an object.

So when you write x=5, some space for x is allocated and this space contains a reference to the Fixnum instance 5, but no new Fixnum instance is created (as you first assumed in your previous post). It's just a reference to the exisiting Fixnum instance.

Very nice blog by the way!</description>
		<content:encoded><![CDATA[<p>Hello,</p>
<p>This doesn&#8217;t appear to me to be entirely correct, Fixnum objects are unique and immutable, so every &#8216;5&#8242; in the system is the same Fixnum instance with the same oid. However, variables can still contain references to this instance, just like every ruby variable contains just a reference to an object.</p>
<p>So when you write x=5, some space for x is allocated and this space contains a reference to the Fixnum instance 5, but no new Fixnum instance is created (as you first assumed in your previous post). It&#8217;s just a reference to the exisiting Fixnum instance.</p>
<p>Very nice blog by the way!</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Frank</title>
		<link>http://www.rubyfleebie.com/understanding-fixnums/#comment-49</link>
		<author>Frank</author>
		<pubDate>Mon, 02 Apr 2007 10:23:47 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/understanding-fixnums/#comment-49</guid>
					<description>Arne, glad you like the blog!

I made my claim based on the ruby documentation : "Fixnum objects have immediate value. This means that when they are assigned or passed as parameters, the actual object is passed, rather than a reference to that object." (http://dev.rubycentral.com/ref/ref_c_fixnum.html)

So how I understand it, is that you always work with the actual object, never with a reference to it.</description>
		<content:encoded><![CDATA[<p>Arne, glad you like the blog!</p>
<p>I made my claim based on the ruby documentation : &#8220;Fixnum objects have immediate value. This means that when they are assigned or passed as parameters, the actual object is passed, rather than a reference to that object.&#8221; (http://dev.rubycentral.com/ref/ref_c_fixnum.html)</p>
<p>So how I understand it, is that you always work with the actual object, never with a reference to it.</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: rifraf</title>
		<link>http://www.rubyfleebie.com/understanding-fixnums/#comment-53</link>
		<author>rifraf</author>
		<pubDate>Mon, 02 Apr 2007 21:45:02 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/understanding-fixnums/#comment-53</guid>
					<description>The hint is that "A Fixnum holds Integer values that can be represented in a native machine word (minus 1 bit). "

Where 'x' has a reference to any other object its object ID will be even. I guess that it is the address of the object in memory. Where x 'is' a fixnum, its object ID is (2 * value + 1). That is - the value is stored in 'x' directly. Any object ID that is odd has the value stored in its upper 31 or 63 bits.

This is done for efficiency. The object stuff is just fakery.

I think I heard that this may change in a later version of Ruby.</description>
		<content:encoded><![CDATA[<p>The hint is that &#8220;A Fixnum holds Integer values that can be represented in a native machine word (minus 1 bit). &#8221;</p>
<p>Where &#8216;x&#8217; has a reference to any other object its object ID will be even. I guess that it is the address of the object in memory. Where x &#8216;is&#8217; a fixnum, its object ID is (2 * value + 1). That is - the value is stored in &#8216;x&#8217; directly. Any object ID that is odd has the value stored in its upper 31 or 63 bits.</p>
<p>This is done for efficiency. The object stuff is just fakery.</p>
<p>I think I heard that this may change in a later version of Ruby.</p>
]]></content:encoded>
				</item>
	<item>
		<title>By: Arne</title>
		<link>http://www.rubyfleebie.com/understanding-fixnums/#comment-60</link>
		<author>Arne</author>
		<pubDate>Wed, 04 Apr 2007 14:28:22 +0000</pubDate>
		<guid>http://www.rubyfleebie.com/understanding-fixnums/#comment-60</guid>
					<description>This is very interesting!

I read the 'native machine word minus 1 bit' before, but I never really understood what that bit is used for.

So in reality there are no Fixnum instances, it's just a big charade :) When the interpreter encounters an odd object reference it knows it really is a Fixnum with value (oid-1)/2.

irb&#62; 0.object_id
=&#62;1
irb&#62; 100.object_id
=&#62;201

Only when it overflows does it become an actual Bignum instance, where different instances with the same value have different oids.

irb&#62; (2**5000).object_id
=&#62; 1073082710
irb&#62; (2**5000).object_id
=&#62; 1073078250

I feel humbled by this learning experience.</description>
		<content:encoded><![CDATA[<p>This is very interesting!</p>
<p>I read the &#8216;native machine word minus 1 bit&#8217; before, but I never really understood what that bit is used for.</p>
<p>So in reality there are no Fixnum instances, it&#8217;s just a big charade <img src='http://www.rubyfleebie.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> When the interpreter encounters an odd object reference it knows it really is a Fixnum with value (oid-1)/2.</p>
<p>irb&gt; 0.object_id<br />
=&gt;1<br />
irb&gt; 100.object_id<br />
=&gt;201</p>
<p>Only when it overflows does it become an actual Bignum instance, where different instances with the same value have different oids.</p>
<p>irb&gt; (2**5000).object_id<br />
=&gt; 1073082710<br />
irb&gt; (2**5000).object_id<br />
=&gt; 1073078250</p>
<p>I feel humbled by this learning experience.</p>
]]></content:encoded>
				</item>
</channel>
</rss>
