From: Charles Oliver Nutter Date: 2008-12-20T00:33:00+09:00 Subject: [ruby-core:20703] Re: [Feature #905] Add String.new(fixnum) to preallocate large buffer Jim Weirich wrote: > There is a slight difference. Array.new(1000) creates an array with a > thousand elements. The proposed String.new(1000) would create a string > with zero characters, but the ability to grow to 1000 characters (umm, > bytes) without internal reallocation. > > I think this difference is enough to warrant different names. Yes, that's a good point; and the resulting array would << to the 1001st element. I suppose then coming up with a common name that works for both would be a good idea. I'm back to liking "buffer" in both cases. String.buffer(1000) produces an empty string that can grow to 1000 bytes without needing to resize/copy. Array.buffer(1000) produces an empty array that can grow to 1000 elements without needing to resize/copy. Whatever is decided, I think it's going to be something people want (need) on 1.8, so I'll probably submit a backport request as well (and perhaps write up a simple extension people can use until then).