From: Shan-leung Maverick WOO Date: 2001-07-05T14:58:10+09:00 Subject: [ruby-talk:17277] Re: extension and GC Yukihiro Matsumoto wrote: > Ah, how do you going to hold dbm reference? RHash structure has no > more room for it. You have to hold dbm reference by either > > * wrap in C struct (as in dbm extension), then associate it via > instance variable. > > * give up inheriting from Hash, probably having Hash for in-memory > cache. If I understand what you mean by "dbm reference" correctly, then this is exactly like the memory that I have to allocate. I would imagine that in the C initialize function I do a malloc and then save the pointer somehow into an instance variable, as you said in first option. I really like this trick 'cos now when the object gets GC'ed, the GC will call my free routine because it will also reclaim the memory by the struct. To put it fairly, I guess here my case is a bit different from dbm: my object is mostly a hash with some special behavior and I even want the user to think it is just a hash with some more methods. So I don't want to re-implement everything hash already supports. In the dbm case, I think going with the second option isn't going to be too bad because most of the methods are going to be overridden anyway. > This is the best I can say without reading your code. I might be > missing something. I hesitate to post my spaghetti code here. By the time my app is done, I will let you know. Once I thought that after I picked up Ruby I would write less C code. But the truth turned out to be that I find it irresistible to use Ruby as extension language for my C apps. So, I end up writing even more C code... :P Thanks a lot for your help. -- All the best, Maverick Woo