"Simon Strandgaard" <0bz63fz3m1qt3001 / sneakemail.com>
>
> There is 2 ways you can inform GC about the new instance.
> #1   rb_define_variable(name, instance);
>      by naming the instance, so it can be accessed by its
>      Ruby-variable-name. Use this if you want to share an
>      instance between Ruby and you extension/embedding code.
>
> #2   rb_gc_register_address(&instance);
>      don't want to assign a name to the instance.
>      Use this if you want to keep some variables *private* to
>      your extension/embedding code.
>      It cannot be accessed from a ruby-script.

This did help ... although I haven't yet tried method# 1

>
> OK.. nice to know.  I was worried that it wouldn't work on windows.
> Perhaps you can add a short guide to rubygarden about how you have
> setup'ed compilation on windows ?

Sure ... first let me learn how to modify the contents of rubygarden.

>
>
> #include <ruby.h>
> int main(int argc, char *argv[]) {
> int n;
> VALUE args[2];
> VALUE klass;
> VALUE instance;
>
> ruby_init();
> args[0] = INT2FIX(4);
> args[1] = rb_str_new2("ok");
> n = 2;
> klass = rb_path2class("Array");
> instance = rb_class_new_instance(n, args, klass);

I tried replacing the above two lines by :

     klass = rb_const_get(rb_cObject, rb_intern("Array"));
     instance = rb_funcall2(klass, rb_intern("new"), argc, argv);

but my program crashed.  Am I missing something ?

> /* tell GC that there is a new instance in town. */
> rb_gc_register_address(&instance);
>
> rb_p(instance);
>
> ruby_finalize();
> return 0;
> }
>

Yes, your code worked ... thanks for sharing your valuable insight.
-- Shashank