• Post Reply Bookmark Topic Watch Topic
  • New Topic

Large objects, memory or fils

 
Zaeed McColin
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys. I'm developing a simple http server with java. well when I send (i.e. 13MB) file to server it eats CPU and memory. really terrible. I sore them in ByteBuffer and String classes. the question is which way is best for storing large objects (file, byte stream,...) is it right that store them to a temp file instead of memory?
Thanks.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no reason whatsoever to keep a big file in memory when disk is fast compared with network bandwidth so write to a temp file.

Just use moderate size byte[] - buffers don't have to be huge - your operating system will be doing some file buffering anyway.

DO NOT USE STRING objects for anything unless you absolutely have Unicode text conversion problems. There is no reason to use a ByteBuffer either since Java IO provides for direct storage to byte[].

Bill

 
Andrei Matyas
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't forget NIOs with memory mapped files. Let your OS do the hard work (lazy loading / paging data / etc..).

Take a look :

http://en.wikipedia.org/wiki/Memory-mapped_file
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!