From: Nikolai Weibull Date: 2010-07-09T19:22:10+09:00 Subject: [ruby-core:31151] Re: Why is there no standard way of creating a String from a char *? On Fri, Jul 9, 2010 at 11:58, Urabe Shyouhei wrote: > (2010/07/09 18:28), Nikolai Weibull wrote: >> I own result, so after creating rbresult I currently have to >> immediately free it. > The problem is the ruby's GC engine cannot know if you own result. ��When GC > reclaims its memory space, any shared memory regions shall not be freed, and > given it cannot say if your variable is for your own or not, the only safe way > for the collector is to copy the memory for its own. (What variable are we talking about here, Ruby or C?) But how is the call to ALLOC_N() in str_new in string.c any different? I mean, ALLOC_N calls vm_xmalloc, which calls malloc. I see no fancy handling of the memory here, more than updating malloc_increase (unless CALC_EXACT_MALLOC_SIZE is on). I���m sorry for being so slow to understand, but I still don���t see why Ruby can���t use the char * that I���ve malloced myself. I want to be able to tell Ruby that ���here, take this char *, I own it, no one else knows about it, guaranteed, and I���m now giving it to you for you to own, I don���t want it anymore���.