From: Robert Klemme Date: 2007-08-06T16:39:55+09:00 Subject: Re: How to reclaim memory without GC.start 2007/8/6, Logan Capaldo : > On 8/4/07, Erik Veenstra wrote: > > > > > buffer = "." * 1024 > > > while STDIN.read(1024, buffer) > > > print buffer > > > end > > > > What's the point of initializing the buffer with 1024 characters, > > instead of just initializing it with an empty string? I must be > > missing something... > > > > Thanks. > > > I think the idea was to do the allocation upfront instead of when witting to > the string. But since that will only happen once, (on the first read) it > seems unnecessary. But I could be wrong. I believe you are right. I probably rather did it for documentary reasons but in fact it's not necessary. There would only be a small but likely unnoticeable advantage if for some reason #read would not read up to limit chars right away. Then there might be multiple reallocations (i.e. until the buffer has reached the limit). But I guess this is not very likely, at least not with file IO. Situation might be different for sockets. Kind regards robert