memory marking problem

J

Joe Bacigalupa

I'm pretty new to Ruby and running into some odd issues with my "mark"
function. Basically I have a situation like this
Code:
void ruby_node_free( void* ptr ){
delete reinterpret_cast<Node*>( ptr );
}
void ruby_node_mark( VALUE self ){
Node* ptr = reinterpret_cast<Node*>(DATA_PTR(self));
if( ptr ){
// these are all ruby arrays
rb_gc_mark( ptr->verts );
rb_gc_mark( ptr->normals );
rb_gc_mark( ptr->uvw );
}
}
void ruby_node_alloc( VALUE klass ){
Node* ptr = new Node;
VALUE object = Data_Wrap_Struct( klass, ruby_node_mark,
ruby_node_free, ptr );
return( object );
}

What happens is when my ruby_node_mark function is called and I grab the
Node* that value is some chode memory value like 0xfdfdfdfd. I'm
wondering if anyone has run into any problems like this where it seems
that some variables are being deleted twice or something like that.
 
T

ts

J> void ruby_node_free( void* ptr ){
J> delete reinterpret_cast<Node*>( ptr );
J> }
J> void ruby_node_mark( VALUE self ){
J> Node* ptr = reinterpret_cast<Node*>(DATA_PTR(self));

The mark function take the same argument than the free function, void *ptr
in your case.


Guy Decoux
 
J

Joe Bacigalupa

ts said:
J> void ruby_node_free( void* ptr ){
J> delete reinterpret_cast<Node*>( ptr );
J> }
J> void ruby_node_mark( VALUE self ){
J> Node* ptr = reinterpret_cast<Node*>(DATA_PTR(self));

The mark function take the same argument than the free function, void
*ptr
in your case.


Guy Decoux

Thanks - that was it - I don't know how I managed to breeze by that
glaring error =) Thank you!

Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,209
Messages
2,571,088
Members
47,686
Latest member
scamivo

Latest Threads

Top