Does it make sense to flush and close?

M

Mischa Berger

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
 
E

Eric Hodel

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,234
Messages
2,571,178
Members
47,809
Latest member
Adisty

Latest Threads

Top