>>>>> "W" == Wai-Sun Chia <waisun.chia / compaq.com> writes:

W> 1. What's the diff between rb_iv_set() and rb_ivar_set()? When do you 
W> use either of them?

 rb_iv_set() is just defined as

   VALUE
   rb_iv_set(obj, name, val)
       VALUE obj;
       const char *name;
       VALUE val;
   {
       ID id = rb_intern(name);
   
       return rb_ivar_set(obj, id, val);
   }

 This mean that rb_ivar_set(obj, rb_intern("foo"), Qnil) is the same than
 rb_iv_set(obj, "foo", Qnil).

 In some case, it's more pratical to define a global ID and then call
 rb_ivar_set() rather than calling rb_iv_set() with a string.


W> 2. When you use:
W> 	VALUE Foo = Data_Wrap_Struct(cFooClass, 0, NULL, data);

 No, Data_Wrap_Struct just allocate an object with the type T_DATA, the
 class cFooClass and associate the free and mark function with it.

 Because generally the last parameter (data in your example) is a pointer
 on a struct, it's not a good idea to give it NULL as the free function
 (like in your example) otherwise you'll have some memory leak in your
 extension. 

W> Does Ruby automatically invoke the .new constructor of FooClass? Which 
W> in turn invokes the .initialize method too?

 Data_Wrap_Struct is generally used *by* the ::new constructor of FooClass.

 If you want to call #initialize, you must make a call to
 rb_obj_call_init() after Data_Wrap_Struct


W> p.s. Do you ever sleep? ;-)

 Hey, I'm in France :-)

pigeon% date
Wed Jul 18 17:08:21 CEST 2001
pigeon% 


Guy Decoux