From: "Eustaquio Rangel de Oliveira Jr." Date: 2005-07-02T06:27:01+09:00 Subject: Re: How and where Fixnum are created -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hey Robert! |> Or any (or some kind of mix of) the two options above? | No, it's a third option: Fixnums are not really objects like others. | With Fixnum the object reference is the object itself. I was checking numeric.c and found rb_cFixnum = rb_define_class("Fixnum", rb_cInteger); and method stuff like rb_define_method(rb_cFixnum, "to_s", fix_to_s, -1); and others. So, there is some method definition there, but so the object itself handle the methods and it's value? | But you don't | see that directly because they are made to mostly work like other | objects. You can only observe it indirectly (like you did) in some | places, namely | | - absence from ObjectSpace Yeah, I needed to open gc. and find "Immediate objects (Fixnums, Symbols, true, false, and nil) are never returned." That gaves me a kind of relief because I was not understanding what was happening. :-) | and maybe some more I don't recall because of my sleepyness. Is sleep a rare thing for developers? I'm on that kind of situation also. Specially because I have a little baby girl who likes to go to sleep late ehehe. :-) | From a | pragmatic perspective this all doesn't really matter: since Fixnums are | immutable (no state changes, no singleton methods) anyway it doesn't | matter whether you have one instance representing a certain numeric | value or multiple. Sure, but is there just one or multiples? :-) Multiples instances will "eat" more memory, on this case? | What in fact does matter in practice is that the | implementation of Fixnums in Ruby provides better performance than | Fixnums that are ordinary objects; in that case all numeric calculations | would suffer because they would incur the additional overhead of object | creation and destruction. HTH Yes, that is really a good thing for sure, the implementation is very good. I'm wondering about that because I'll need to explain that kind of thing to some developers that does not know Ruby and I'm sure they will ask me something about this case (specially the python ones). So I need to try to resume the behaviour for them. What is still confusing me is, as you said, is that there is no additional overhead of object creating and destruction, so I can presume that we deal directly with their values, but where are their methods? Sorry to bore you, but I need a "light" about that (or more sleep and rest to think better). :-) Thanks! - ---------------------------- Eust�quio "TaQ" Rangel eustaquiorangel@yahoo.com http://beam.to/taq Usu�rio GNU/Linux no. 224050 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.7 (GNU/Linux) iD8DBQFCxbURb6UiZnhJiLsRAjECAJ0VhJxTzg6iPJEo6/dJ1qQ2vVbX4QCgvZHv ARvvf3e0C3xHZdi27VjoAd0= =Sccr -----END PGP SIGNATURE-----