[ruby-core:93865] [Ruby master Feature#15923] New independent string without memcpy

From: aladjev.andrew@...
Date: 2019-07-21 19:21:32 UTC
List: ruby-core #93865
Issue #15923 has been updated by puchuu (Andrew Aladjev).


nobu (Nobuyoshi Nakada) wrote:
> It should be OK when passing the buffer from callers, but doesn't work with a library which returns a buffer allocated inside.
> 
> FYI: you can allocate the buffer by `rb_str_new(NULL, size_you_want)` at once.

Thanks all, I see. Ruby has some kind of internal memory allocation mechanism and it is not recommended to use strings allocated outside.

Integration of `rb_str_resize` into buffer growth mechanism is a good but complex solution. I will keep string copy.

----------------------------------------
Feature #15923: New independent string without memcpy
https://bugs.ruby-lang.org/issues/15923#change-79777

* 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: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next