From: Gaffer Date: 2003-05-18T23:14:38+09:00 Subject: Re: ruby garbage collection i've switched over all my 'concrete' classes quite easily, looks like i'll have to do some placement new (finally an excuse to use it) tricks for my more complex classes but its all working fine now, cheers :) -----Original Message----- From: Simon Strandgaard [mailto:0bz63fz3m1qt3001@sneakemail.com] Sent: Monday, May 19, 2003 12:10 AM To: ruby-talk ML Subject: Re: ruby garbage collection On Sun, 18 May 2003 23:48:28 +0900, Gaffer wrote: > so i didnt know you could override the singleton method new for a class, to > do the Data_Make_Struct, Yeah its a bastard :-) > so i was wrapping an outer 'husk' object with a member variable @data which > was pointing to a Data_Wrap_Struct around my c++ object created with new Yes.. My alloc/free looks something like this (ruby-1.8.0) void Free(Klass *p) { delete p; } VALUE Alloc(VALUE self) { Klass* p = new Klass(); return Data_Wrap_Struct(self, 0, Free, p); } void KlassInit() { VALUE h = rb_define_class("Klass", rb_cObject); rb_define_alloc_func(h, Alloc); } -- Simon Strandgaard