From: Tim Hunter Date: 2002-10-24T23:43:15+09:00 Subject: Re: On Using Data_Wrap_Struct No. Remember that Ruby will allocate storage from its heap for the array that you're using and for the copies of n and msg that you make when you do INT2FIX(n) and rb_str_new2(msg) (or rb_str_new(msg, 64)). As long as you need the array, (which I assume is as long as the Foo object is alive) you must mark its VALUE whenever gc calls Foo's mark function. Otherwise gc will delete it out from under you. The array, in turn, will take care of marking the VALUEs it contains, including the n and msg VALUEs you push on it. When you create a Foo object with Data_Wrap_Struct or Data_Make_Struct, include a pointer to a "mark function". GC will call the mark function periodically, during the "mark" part of its mark & sweep. It's the mark function's responsibility to mark any VALUEs contained in the Foo object so that gc can tell that they're still alive. Just add a call to rb_gc_mark(my_ary) in the mark function. This is from the Pickaxe, chapter 17: "In order to participate in Ruby's mark-and-sweep garbage collection process, you need to define a routine to free your structure, and possibly a routine to mark any references from your structure to other structures. Both routines take a void pointer, a reference to your structure. The mark routine will be called by the garbage collector during its ``mark'' phase. If your structure references other Ruby objects, then your mark function needs to identify these objects using rb_gc_mark(value). If the structure doesn't reference other Ruby objects, you can simply pass 0 as a function pointer. " Good luck! On Thu, 24 Oct 2002 00:53:16 GMT, Mark Probert wrote: > >Tim, > >Thank you so much for the info, it has done the trick. > >One question on your post... > >"Tim Hunter" wrote: >> >> ...Don't forget to mark the array VALUE within >> Foo's mark function. >> >I would need to do this if I dynamically allocate >storage for msg, yes? If I statically allocate it > > struct _bar { > int n; > char msg[64]; > } Bar; > >then I assume that the standard mechanisms will clean >up the mess I make? > >Thanks, again. > >-mark.