From: "dtuttle1@..." Date: 2007-07-18T02:30:08+09:00 Subject: Re: How to reclaim memory without GC.start On Jul 17, 2:51 am, "Robert Klemme" wrote: > 2007/7/17, Joel VanderWerf : > > > > > Travis D Warlick Jr wrote: > > > Joel VanderWerf wrote: > > >> Travis D Warlick Jr wrote: > > >>> Lionel Bouton wrote: > > > >>> while buffer[0...512] = file.read(512) > > > >> Do you mean file.read(512, buffer) ? > > > > Ahh, yes. That would be an much prettier way to do it. > > > > while file.read(512, buffer) > > > It's not just prettier. With an assignment like > > > buffer[0...512] = file.read(512) > > > there is an intermediate string that instantly becomes garbage. > > There is a better way to do it: > > buffer = "." * 1024 > while STDIN.read(1024, buffer) > print buffer > end > > So the original code should be rewritten as > > File.open file_path do |file| > buffer = "." * 512 > while file.read(512, buffer) > stream_host_connection.write buffer > stream_host_connection.flush > end > end > > The main point being here to reuse the buffer. No C extension needed. > Seehttp://www.ruby-doc.org/core/classes/IO.html#M002295 > > Kind regards > > robert It works perfectly! Thanks everyone!