<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Understanding Fixnums</title>
	<atom:link href="http://www.rubyfleebie.com/understanding-fixnums/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rubyfleebie.com/understanding-fixnums/</link>
	<description>Because programming should be fun</description>
	<lastBuildDate>Wed, 04 Jan 2012 05:17:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Arne</title>
		<link>http://www.rubyfleebie.com/understanding-fixnums/comment-page-1/#comment-60</link>
		<dc:creator>Arne</dc:creator>
		<pubDate>Wed, 04 Apr 2007 14:28:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.rubyfleebie.com/understanding-fixnums/#comment-60</guid>
		<description>This is very interesting!

I read the &#039;native machine word minus 1 bit&#039; before, but I never really understood what that bit is used for.

So in reality there are no Fixnum instances, it&#039;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&gt; 0.object_id
=&gt;1
irb&gt; 100.object_id
=&gt;201

Only when it overflows does it become an actual Bignum instance, where different instances with the same value have different oids.

irb&gt; (2**5000).object_id
=&gt; 1073082710
irb&gt; (2**5000).object_id
=&gt; 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 :) 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>
	<item>
		<title>By: rifraf</title>
		<link>http://www.rubyfleebie.com/understanding-fixnums/comment-page-1/#comment-53</link>
		<dc:creator>rifraf</dc:creator>
		<pubDate>Mon, 02 Apr 2007 21:45:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.rubyfleebie.com/understanding-fixnums/#comment-53</guid>
		<description>The hint is that &quot;A Fixnum holds Integer values that can be represented in a native machine word (minus 1 bit). &quot;

Where &#039;x&#039; 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 &#039;is&#039; a fixnum, its object ID is (2 * value + 1). That is - the value is stored in &#039;x&#039; 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 &#8211; 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: Frank</title>
		<link>http://www.rubyfleebie.com/understanding-fixnums/comment-page-1/#comment-49</link>
		<dc:creator>Frank</dc:creator>
		<pubDate>Mon, 02 Apr 2007 10:23:47 +0000</pubDate>
		<guid isPermaLink="false">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 : &quot;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.&quot; (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; (<a href="http://dev.rubycentral.com/ref/ref_c_fixnum.html" rel="nofollow">http://dev.rubycentral.com/ref/ref_c_fixnum.html</a>)</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: Arne</title>
		<link>http://www.rubyfleebie.com/understanding-fixnums/comment-page-1/#comment-48</link>
		<dc:creator>Arne</dc:creator>
		<pubDate>Mon, 02 Apr 2007 10:07:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.rubyfleebie.com/understanding-fixnums/#comment-48</guid>
		<description>Hello,

This doesn&#039;t appear to me to be entirely correct, Fixnum objects are unique and immutable, so every &#039;5&#039; 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&#039;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>
</channel>
</rss>

