Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to get the bytes required to load a file in memory?  RSS feed

 
Rohit Kumar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to get the bytes required to load a file in memory?
or,
how to caculate the number of bytes the file takes to load in memory?
 
Norm Radder
Rancher
Posts: 1733
22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems like too simple a question. If you're not talking about the File.length() value, then are you refering to how many bytes the JVM takes to support the memory that will hold the file's bytes? Or what?
 
Rohit Kumar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to know, when i insert a 1 MB file (say an jpeg image), how much bytes memory uses to load this file? And how to calculate it?

using file.length() it returns size of original file size (disk size).
I would like to know actual size in memory.

for example few image softwares shows you the disk space of image and memory space to load the image.
 
Rohit Kumar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am doing something like this, please let me know is it right way, or is there any other way?

Runtime runtime = Runtime.getRuntime();
long before = runtime.totalMemory();

// read the file//

long after = runtime.totalMemory();
System.out.println("Total memory required : " + (after -before)/1024/1024);
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!