Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Writing to a file



At 02:14 PM 5/15/2001 -0400, Jon Lucenius wrote:
That did the trick - I am sure the other sample sent in would work as
well. Now my question is which way is better of the following two
methodologies: (most code snipped for brevity)

1) ** USING BUFFERED WRITER - EXAMPLE FROM JAVA.SUN.COM FOR Java 1.2 **

If you fail to use a buffered writer, then every write potentially can hit the disk. I have seen orders of magnitude speedups when switching to buffered readers and writers. Also, different machines react differently - not buffering on the MacOS under OS 9 causes a severe performance hit, which seems greater than that seen under Linux.

As a side note, the default buffered writers are way too small for modern caching - use at least 8kb, and consider 64kb or 1MB. (If you use 1MB make very, very, very sure that you flush the buffer and close the file. I also explicitly null out the reference to it to maximize the chance of the GC catching it quickly.)

Finally blocks can be a great friend for circumstances like this where you want to make very, very sure that something is closed regardless of what happened in the mean time.

Scott
Scott Ellsworth
email@hidden


References: 
 >Re: Writing to a file (From: James Bucanek <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.