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
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)?
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
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
shared string used for example in string and regexp. Just an example with
^^^^^^
hash
regexp
sorry,
Guy Decoux