[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Detaching free function from String in C API

Alex Fenton

4/1/2008 11:46:00 AM

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
2 Answers

ts

4/1/2008 12:03:00 PM

0

Alex Fenton wrote:
> 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



Alex Fenton

4/1/2008 2:31:00 PM

0

ts wrote:
> Alex Fenton wrote:
>> 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.

Perfect, thanks. I will read the source and ponder

alex