Kurt Stephens

Nerd Up!

Recent comments

Random image

Latest image

Syndicate

Syndicate content

Browse archives

« August 2008  
Mo Tu We Th Fr Sa Su
        1 2 3
4 5 6 7 9
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

C

Ruby Internals: Why RUBY_FIXNUM_FLAG should be 0x00

Kurt on Tue, 2008-01-01 04:06.

Type tags in Ruby VALUE

Internally, values in Ruby are 32-bit (at least for 32-bit processors). Some of the least-significant bits are used to store type information. See the VALUE definition in include/ruby/ruby.h. Using type tag bits avoids allocating additional memory for commonly-used immutable values, like integers.

Ruby uses a single-bit tag of 0x01 as the Fixnum type tag. The remaining bits, are used to store the Fixnum’s signed value. This is an immediate value; it doesn’t require storage for the Fixnum value to be allocated, unlike the heap space that would be required for a String. Other types will use different tag bits.


Syndicate content