From: luke.gru@... Date: 2019-06-15T13:42:53+00:00 Subject: [ruby-core:93160] [Ruby trunk Feature#15923] New independent string without memcpy Issue #15923 has been updated by luke-gru (Luke Gruber). I think what puchuu is asking is if he can pass a malloc'd string to a ruby function that will create a new string object that frees the given underlying buffer when the string object is destructed. Having read the code, I didn't come upon such a case but I imagine it's possible with a slight hack (untested by me, however): VALUE str = rb_str_new_static(buffer, buflen); /* no malloc or memcpy done here, just ownership change of buffer */ RUBY_FL_UNSET(str, STR_NOFREE); /* STR_NOFREE isn't actually defined in internal.h unfortunately, it's currently same as FL_USER18, but could change. */ Perhaps a new ruby string creation function would be useful? Something like rb_str_new_take(). Just a thought. ---------------------------------------- Feature #15923: New independent string without memcpy https://bugs.ruby-lang.org/issues/15923#change-78601 * Author: puchuu (Andrew Aladjev) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- Hello. I've just tried to implement extension for ruby that will provide large binary strings. I've inspected latest ruby source code and found 2 functions: _rb_str_new_ and _rb_str_new_static_ . * _rb_str_new_ allocates new memory and uses _memcpy_ to copy from source string to new memory. * _rb_str_new_static_ uses existing source string as it is, but adds _STR_NOFREE_ flag. Is it possible to create independent string from source string without memcpy that will be freed automatically? Thank you. -- https://bugs.ruby-lang.org/ Unsubscribe: