From: "mame (Yusuke Endoh)" <mame@...> Date: 2012-10-27T10:50:06+09:00 Subject: [ruby-core:48424] [ruby-trunk - Feature #905] Add String.new(fixnum) to preallocate large buffer Issue #905 has been updated by mame (Yusuke Endoh). ko1 (Koichi Sasada) wrote: > Who can judge this ticket? > I can't understand this issue because there is long discussion. > Could anyone summarize a conclusion? Not concluded, but currently we know: - This feature provides "a Ruby-level workaround" for a poor realloc implementation on some runtime, such as JVM, and possibly os x. - But at least, Linux (precisely, libc?)'s realloc is well implemented. So this feature is meaningless in practice, in such environment. -- Yusuke Endoh <mame@tsg.ne.jp> ---------------------------------------- Feature #905: Add String.new(fixnum) to preallocate large buffer https://bugs.ruby-lang.org/issues/905#change-31745 Author: headius (Charles Nutter) Status: Feedback Priority: Normal Assignee: matz (Yukihiro Matsumoto) Category: Target version: 2.0.0 =begin Because Strings are used in ruby as arbitrary byte buffers, and because the cost of growing a String increases as it gets larger (especially when it starts small), String.new should support a form that takes a fixnum and ensures the backing store will have at least that much room. This is analogous to Array.new(fixnum) which does the same thing. The simple implementation of this would just add a Fixnum check to the String.new method, and the result would be an empty string with that size buffer. This would allow heavy string-appending algorithms and libraries (like ERb) to avoid doing so many memory copies while they run. =end -- http://bugs.ruby-lang.org/