Terminated Object Error. Help Needed

Here is my sample code:-

In ruby file-\

require ‘test’
talloc = Myalloc::MyClass.new(“New”);
talloc.defin(1000000) // Creates an array of size 1000000
talloc.alloc(‘3d’,31) // Allocates the String ‘3d’ at index 31
myA=talloc.use(31) // Fetch the string from index 31 and store in myA

The ‘use’ function in C is coded as:–

VALUE use(VALUE self,VALUE pos)
{
int arr_pos = NUM2INT(pos);
printf(“Index Contains:%s\n”,array[arr_pos]); // array is a char **
return NUM2CHR(array[arr_pos]);

}

But when i run the above ruby code it is giving me an error which I
can’t figure out what it means and whats wrong going on.

The error is:–

test.rb:5:in use': methodrespond_to?’ called on terminated object
(0x63da10) (NotImplementedError)
from test.rb:5

Can anyone explain to me this error and how to get rid of it?

Thanks
Tridib

On Apr 4, 2012, at 13:16 , Tridib B. wrote:

The ‘use’ function in C is coded as:–
can’t figure out what it means and whats wrong going on.

The error is:–

test.rb:5:in use': methodrespond_to?’ called on terminated object
(0x63da10) (NotImplementedError)

The last line uses array[arr_pos] but you aren’t setting array in your
function. You should probably be using something accessed via self.

How to use with self?

I have to access the string which is at array[arr_pos].

Regards
Tridib

On Thu, Apr 05, 2012 at 06:17:29AM +0900, Tridib B. wrote:

How to use with self?

I have to access the string which is at array[arr_pos].
Guess that GC ate it. Do you rb_gc_mark and array?

Regards
Tridib


Posted via http://www.ruby-forum.com/.

Too few computrons available.

On Wed, Apr 4, 2012 at 11:17 PM, Tridib B.
[email protected] wrote:

How to use with self?

Well, apparently you wrote methods #defin and #alloc in class
Myalloc::MyClass - maybe even in C. So only you know how they
associate state with self. If you use Ruby’s standard mechanisms
(i.e. instance variables) there should be any number of examples in
source code which access via state. Other than that, if you associate
state with an instance in a custom way only you can know how to access
it.

Cheers

robert

“Ondřej Bílka” [email protected] wrote in post #1055109:

On Thu, Apr 05, 2012 at 06:17:29AM +0900, Tridib B. wrote:

How to use with self?

I have to access the string which is at array[arr_pos].
Guess that GC ate it. Do you rb_gc_mark and array?

I do have mark function. The array is a global declaration. When I try
to run this code

myA=talloc.use(31) // Fetch the string from index 31 and store in myA

VALUE use(VALUE self,VALUE pos)
{
int arr_pos = NUM2INT(pos);
printf(“Index Contains:%s\n”,array[arr_pos]); // array is a char **
return NUM2CHR(array[arr_pos]);

}

Everything is working fine the printf statement is giving me back the
string which i allocated ‘3d’ but don’t know whats messing it up at the
return statement.