aspose file tools*
The moose likes I/O and Streams and the fly likes Setting buffer size Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Setting buffer size" Watch "Setting buffer size" New topic
Author

Setting buffer size

Mark Reyes
Ranch Hand

Joined: Jul 09, 2007
Posts: 426
Hi All,

I really havent known this but I just would like to know.

Its about setting a buffer when reading on inputstream. I usually do this.


But I often see this:



or like this:



or like this:



I tried to google but can find the right response so I decided to post.
Can someone orient me on the rule when it comes to setting a buffer?


Sean Clark ---> I love this place!!!
Me ------> I definitely love this place!!!
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
If you are asking whether you should specify 2048 or 2 * 1024, there is no rule. Some programmers consider 2 * 1024 to be more informative to a person reviewing the code. 1024 is 1K. if you need a buffer size, for example, 12K, does it provide more information to the reader to say 12 * 1024 or 12288? Specifying 2 * 1024 is not less efficient at runtime than specifying 2048 because the compiler makes the calculation.
Mark Reyes
Ranch Hand

Joined: Jul 09, 2007
Posts: 426
Hi Tom,



I think so also..

I think your response answers half of my question.
But then, I would like to know when it is adviseable to create a buffer such as



and when it is right to just create a 1KB buffer.



My guess is that is it related to the file size???
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

The ideal size is the page size used, but that's determined by the OS and/or the file system. Optimal buffer sizes on one system may be just so-so on other systems.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Mark Reyes
Ranch Hand

Joined: Jul 09, 2007
Posts: 426
Hi Rob,

The ideal size is the page size used, but that's determined by the OS and/or the file system. Optimal buffer sizes on one system may be just so-so on other systems.


Thanks. So does it mean, I could tweak this anytime and check if the performance is still good?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

mark reyes wrote:Hi Rob,

The ideal size is the page size used, but that's determined by the OS and/or the file system. Optimal buffer sizes on one system may be just so-so on other systems.


Thanks. So does it mean, I could tweak this anytime and check if the performance is still good?


Sure. Try different buffer sizes and transfer the same file, timing how long it takes to do the transfer. Make sure you use a large file otherwise you'll be including a larger amount of code unrelated to file copying.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Setting buffer size