From: "Bartosz Dziewoński" Date: 2012-03-25T03:26:47+09:00 Subject: Re: Ruby speed compared to C in a simple calculations. W dniu 24 marca 2012 18:55 użytkownik Josh Cheek napisał: > Numbers are actual objects that must be allocated, for example. Fun fact: it's thankfully not *that* bad. Numbers up to 2**30-1 are not actually allocated; instead, they're magically stored in the C pointer which would normally point at the location of associated object. Symbols are handled similarly (that's why you should always use them instead of strings when the actual string values does not matter). See for yourself. For regular objects, #object_id returns numerical values of location in memory where it is stored (that is, values of C pointer to this object). But... irb(main):001:0> 1.object_id => 3 irb(main):003:0> 100.object_id => 201 irb(main):005:0> 120.object_id => 241 irb(main):007:0> 200.object_id => 401 Here you see a pattern: small numbers' object_id are equal to the number, doubled, plus one. irb(main):015:0> 2**30-1 => 1073741823 irb(main):016:0> (2**30-1).object_id => 2147483647 irb(main):017:0> (2**30-1).class => Fixnum The pattern still holds. irb(main):018:0> 2**30 => 1073741824 irb(main):019:0> (2**30).object_id => 6594348 irb(main):020:0> (2**30).class => Bignum No more! Our number was promoted to a Bignum, which is actually allocated separately - the object_id value is no longer magical, it's just a straight pointer to a location in memory. (It will be different on your machine.) -- Matma Rex