From: Kurt Stephens Date: 2010-03-05T09:13:00+09:00 Subject: [ruby-core:28491] [Feature #905] Add String.new(fixnum) to preallocate large buffer Issue #905 has been updated by Kurt Stephens. +1 Preallocation of String would be immensely useful in large ERB templates. So much so, I was looking to patching into rb_str_resize(str, len) with a method, to get around related performance issues. Ruby Strings already support the difference between the string length and the allocated buffer size -- we need to expose it and ensure that Strings do not automatically "shrink" the internal String buffers. There should probably be a method to explicitly shrink the internal buffer, if needed. From what I can tell string growth is roughly O(log2 N) because of the power-of-2 buffer resizing. For large buffers making this O(1) for large strings helps performance and reduces malloc() memory fragmentation. ---------------------------------------- http://redmine.ruby-lang.org/issues/show/905 ---------------------------------------- http://redmine.ruby-lang.org