On 7/8/10, Nikolai Weibull <now / bitwi.se> wrote:
> Hi!
>
> Why is there no standard way of creating a String from a char *?  All
> the rb_str_new* functions take a const char * and copy it.  I would
> like a function that would create a String from a char *, that is,
> without copying it.

In order for this to work, you have to ensure that the c string you
pass to rb_str_new_whatever does not get deallocated (or changed)
until ruby is done with it. Since, in general, you don't know when the
String gets garbage collected, this effectively means the c string
must never be deallocated. I think that the danger that the user would
free the c string and the uncertainty over lifetime are the reasons
why ruby always insists on copying the string data.