[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-core
Subject:    Re: Where to start
From:       dreamhead <dreamhead.cn () gmail ! com>
Date:       2006-12-31 3:30:47
Message-ID: bdee78470612301930x56322d58vc930f60d664418f9 () mail ! gmail ! com
[Download RAW message or body]

Because VALUE is NOT just a POINTER, such as Fixnum.
In Ruby, Fixnum is stored as long, not a pointer.

In modern machine, pointer should be aligned, so the last two bits of
the pointer should be 0. So the VALUE whose the last two bits is not 0
could be used in other places.

Fixnum set the last bit to 1, so you can see the following code in Ruby.h
#define FIXNUM_FLAG 0x01
#define INT2FIX(i) ((VALUE)(((long)(i))<<1 | FIXNUM_FLAG))
#define FIXNUM_P(f) (((long)(f))&FIXNUM_FLAG)

The cost for creating a fixnum is very low, so there's no need to
maintain integer object cache like in Python and Java to improve
performance.

The above is just an example for VALUE. In Ruby, nil, true, false,
symbol are all special VALUE.

You can get more information from RHG.

2006/12/30, Strong Cypher <cypherstrong@gmail.com>:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> a think not easy in this language it's the original doc, japan so ...
> I hope a fully english version will be available soon, it could be more easy
> for helping
>
> But thx for that, effectivly it sould be a pointer
>
> why don't call it POINTER so ??? hihi
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (MingW32) - WinPT 1.0.1
>
> iD8DBQFFlidFEg3iyspSWPARArXWAJsHHH2CfGxe3Q4BcJNb2ek3qjccdACfa1HS
> apXd0Lsj38lYwT/6O9Sv5ic=
> =mSrI
> -----END PGP SIGNATURE-----
>
>


-- 
Everything is simple!

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic