• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Setting buffer size

 
Ranch Hand
Posts: 426
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 426
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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???
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Mark Reyes
Ranch Hand
Posts: 426
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic