[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Does it make sense to flush and close?

Mischa Berger

2/15/2007 10:39:00 PM

Hi everyone,

Consider the following code:

# Save the file on the file system
File.open(self.temp_path, 'wb') do |f|
while buff = myfile_field.read(4096)
f.write(buff)
f.flush
end
end

Is there any benefit in flushing in the code above?
Does this mean 4096 bytes of memory are freed everytime flush is called?

I'm trying to grasp what exactly happens and if there are any benefits
or drawbacks.

Thanks,

Mischa

--
Posted via http://www.ruby-....

1 Answer

Eric Hodel

2/16/2007 7:17:00 PM

0

On Feb 15, 2007, at 14:39, Mischa Berger wrote:
> Hi everyone,
>
> Consider the following code:
>
> # Save the file on the file system
> File.open(self.temp_path, 'wb') do |f|
> while buff = myfile_field.read(4096)
> f.write(buff)
> f.flush
> end
> end
>
> Is there any benefit in flushing in the code above?

Unlikely. It only ensures the data is written to the file.

> Does this mean 4096 bytes of memory are freed everytime flush is
> called?

No. The GC will clean up memory as necessary.

> I'm trying to grasp what exactly happens and if there are any benefits
> or drawbacks.

fflush(3) is called more often, that's all.