From: matz@... (Yukihiro Matsumoto) Date: 1999-07-19T16:34:44+09:00 Subject: [ruby-talk:00506] Re: One question about classes written in C. I think Cle made mistake; forwarded. ------- Start of forwarded message ------- From: Clemens Hintze To: matz@netlab.co.jp (Yukihiro Matsumoto) Subject: Re: [ruby-talk:00502] One question about classes written in C. Date: Mon, 19 Jul 1999 08:19:44 +0200 On Mon, 19 Jul 1999, you wrote: >Hi, > >In message "[ruby-talk:00502] One question about classes written in C." > on 99/07/16, Clemens.Hintze@bln.sel.alcatel.de writes: > [...] >As Gotoken said, use Data_Make_Struct to avoid future magic number >conflict. Type magic number should be lower than 0x80, so We have >only 127 possible magic numbers. I'd like to reserve them for the >future internal types. In this case, you should not only like, but enfore usage only for internal types! :-) [...] >Hmm, I think using is-a too much is bad funciton; use polymorphism >instead, if possible. I think I'm not going to add it not to >encourage using IS_A. In my class I need that function in the constructor and in the `+' and `-' method. In the constructor I have to ensure that only `Numeric's are used to initialize my instance. In the both arithmetic methods, I have to know, whether they operate on an instance of that class or not! Because adding a point to a point is a little bit different from adding a scalar to a point. Is there another function to detect these? [...] >Foe the plaforms which does not have alloca(), we supply portable (but >inefficient) substitution. See missing/alloca.c. Woah! I have not detect the `missing' directory yet! Sorry. :-) [...] >Actually no, at least for Python (and maybe for Tcl, but not for >Perl). Python uses reference counting, so that circular references >would not be collected. Python users should aware it uses non "true >GC", and cut the unused circular references, otherwise memory leak >will happen. Okay, here you are right! I have forgot about the circular references. > >Perl do use reference counting, but it also do the real GC (mark and >sweep) periodically. So it can claim to have "true" GC. No! :-) Perl invokes it true GC only on interpreter shutdown, not periodically, AFAIK. That happens exactly once during a program run ;-) It is only introduced to allow Perl to be embed into other programs, and run into a thread. If the interpreter thread shutdown, all memory will reclaimed, so no memory leaks will remain. [...] >| AND NEARLY NO CALL TO `free(ptr)'. If I do not know the >| dependencies, I really can get the impression, that there is a >| "real" GC on work! > >Maybe I had better emphasize `less memory management in extensions', >not "true GC". :-) Perhaps emphase "true GC" with breaking circular references on the script side features, and `less memory management in extensions too' on the C side? :-) [...] >Hmm, instances are many. The relation between C variable and instance >variables should be 1 to n relation. How can Ruby handle that >relation? Could you explain more about your idea? No... I mean yes... I mean $%&=A7$ Let me sort a little bit... okay! I mean, you could allow to connect an instance variable with an address, couldn't you? One would have doing that connection in the `initialize' function again and again. So it would be no 1-n relation. One instance variable - --> one memory location under C. Somthing like: rb_connect_var(rb_intern("@x"), point->x); Perhaps we could also going the way to allow to tie a variable together with a method. Like your functions rb_define_hooked_variable, rb_define_virtual_variable. But for instance variables also. Perhaps it could also be nice to have that feature on Ruby level too. [...] >I advice you that 'do not use T_POINT' in your extension. :-) I have already forgot about that ;-) > > matz. \cle ------- End of forwarded message -------