Detaching free function from String in C API

A

Alex Fenton

Hi

In a C extension, you can unset the 'free' function that will be called
when an object is garbage collected with something like:

RDATA(obj)->dfree = 0;

This is useful if you know that whatever C library you're interfacing to
will take care of free-ing the C structure.

Is the same thing is possible with an in-built ruby String object, to
set it so that the underlying char* contents will not be freed when the
String is GC'd?

thanks
alex
 
T

ts

Alex said:
Is the same thing is possible with an in-built ruby String object, to
set it so that the underlying char* contents will not be freed when the
String is GC'd?

Look at mmap (in RAA), when you write

m = Mmap.new("aa")

the object in `m' is in reality a String object and mmap make in
sort that ruby will never free the char * content, otherwise it
will crash.

Guy Decoux
 
A

Alex Fenton

ts said:
Look at mmap (in RAA), when you write

m = Mmap.new("aa")

the object in `m' is in reality a String object and mmap make in
sort that ruby will never free the char * content, otherwise it
will crash.

Perfect, thanks. I will read the source and ponder

alex
 

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,289
Messages
2,571,435
Members
48,121
Latest member
ColinHibne

Latest Threads

Top