Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7541037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:47:25+00:00 2026-05-30T07:47:25+00:00

Im writing a Ruby extension and Im using the function Data_wrap_struct . In order

  • 0

Im writing a Ruby extension and Im using the function Data_wrap_struct.

In order to participate in Ruby’s mark-and-sweep garbage collection process, I need to define a routine to free my structure, and a routine to mark any references from my structure to other structures. I pass the classic free function to free the memory but I dont know how to use a mark function.

my structs sound like this

typedef struct
{
  int x;
  int y;
} A;

typedef struct
{
  A collection[10];
  int current;
} B;

I think that I need a mark function to mark the references in collection of struct B.

Someone can show me a example to see how a mark function works?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T07:47:26+00:00Added an answer on May 30, 2026 at 7:47 am

    The mark function is used to mark any Ruby objects that your C structure owns.

    typedef struct {
        VALUE ruby_object;
    } MyStruct;
    
    void mark(void * p) {
        /* p is the wrapped pointer to the MyStruct instance */
        MyStruct * my_struct = (MyStruct *) p;
        rb_gc_mark(my_struct->ruby_object);
    }
    

    If the object owned by your structure isn’t marked, the garbage collector could sweep it and your code may end up trying to use a finalized object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a Ruby C Extension where I'm using math.h . It's being compiled
I'm writing an Ruby on Rails app using a legacy database. The problem I'm
I am writing some Ruby code, not Rails, and I need to handle something
I'm writing a Ruby 1.9 C extension and I want to do the following
I'm writing a ruby program that need raw cpu power (I know ruby is
I am in the process of writing a Ruby script/app that helps me compiling
I'm writing a Ruby C Extension. I will be compiling it under Windows and
I'm very new to C and I'm writing a Ruby C Extension. One of
I'm writing a ruby on rails application using mongoid and I'm wondering about the
I'm writing a Ruby gem using the {key: 'value'} syntax for hashes throughout my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.