From: Eric Hodel Date: 2011-08-03T05:03:16+09:00 Subject: Re: Help in Pointer On Aug 1, 2011, at 6:11 PM, Tridib Bandopadhyay wrote: > I got to know from this forum before that the Garbage Collector just > scans the stack looking for pointers. So, if we allocate a pointer and > hide data behind the pointer the Garbage Collector won't see pointers > which aren't on the stack. > > As I am working on Garbage Collector and want to implement manual memory > deallocation so I need to hide data from the garbage collector applying > the above technique. You can inform the garbage collector of your pointer through Data_Wrap_Struct and Data_Make_Struct. From README.EXT: > 3.3 Encapsulate C data into a Ruby object > > To wrap and objectify a C pointer as a Ruby object (so called > DATA), use Data_Wrap_Struct(). > > Data_Wrap_Struct(klass, mark, free, ptr) > > Data_Wrap_Struct() returns a created DATA object. The klass argument > is the class for the DATA object. The mark argument is the function > to mark Ruby objects pointed by this data. The free argument is the > function to free the pointer allocation. If this is -1, the pointer > will be just freed. The functions mark and free will be called from > garbage collector. Does this answer your questions? For further reading: http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/README.EXT?view=markup