creating new Ruby strings in C

C

Charles Mills

Some questions about the rb_str_new..rb_str_new5 functions.
Is it possible for RSTRING(str)->ptr to reference a C string or part of a
C buffer with out eventually calling free on ptr (and without stopping
the gc)?
I imagine the gc will eventually call free on ptr for any Ruby string
created with rb_str_new2.
What are str_new3 and str_new4 used for?
Thanks in advance,
Charlie
 
T

ts

C> Is it possible for RSTRING(str)->ptr to reference a C string or part of a
C> C buffer with out eventually calling free on ptr (and without stopping
C> the gc)?

yes, and no : see mmap

mmap can be seen as a delegator : in some case, it just create a String
object and call the corresponding String method, but it's very carefull
about the gc

C> What are str_new3 and str_new4 used for?

shared string used for example in string and regexp. Just an example with
regexp

a = "aaa"
/.*/ =~ a
a << "b"


After the match, $~ and `a' "share" internally the same string, but the
variable `a' is marked "copy-on-write". When ruby want to modify `a', it
first duplicate the string and make the modification.


Guy Decoux
 
T

ts

t> shared string used for example in string and regexp. Just an example with
^^^^^^
hash
t> regexp

sorry,


Guy Decoux
 

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

Forum statistics

Threads
474,142
Messages
2,570,818
Members
47,362
Latest member
eitamoro

Latest Threads

Top