• Post Reply Bookmark Topic Watch Topic
  • New Topic

File size and Heap space

 
Collin Goredema
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I am writing to a file in Java, does the size of the file take space from the allocated memory heap? How would a 129mb file affect performance?
 
Jim Baiter
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tested this with a 500M+ file (the Oracle 8i zip distribution) on Win2K. The code/output is below. When the file is opened I noticed 5M being acquired on the windows memory monitor panel in the task manager but that was about it.
import java.io.*;
public class test {
public static void main(String[] args) {
try {
System.out.println(Runtime.getRuntime().totalMemory()/1024 + "K");
FileOutputStream fos = new FileOutputStream("oracle817ntee.zip", true);
System.out.println(Runtime.getRuntime().totalMemory()/1024 + "K");
Thread.currentThread().sleep(10000);
System.out.println(Runtime.getRuntime().totalMemory()/1024 + "K");
fos.close();
}
catch(Exception e) { e.printStackTrace(); }
}
}
C:\temp>java test
1984K
1984K
1984K
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!