K
Kaidi
Hi,
Anyone know how to write/read objects to/from file faster than Java's
writeObject?
My program needs to write a ArrayList to file, which I found is very
very
slow and memory consumming using writeObject.
The arraylist is about 5000 size, each item of it is another arraylist
of about 3500 size, and each item of that is a Float. (So it is a
nested arraylist, with inner most object Float)
So I would expect the size of it should be around 5000*3500*2/1000000
= 35M byte, plus overhead of class/object.
However, I found when I try to use this code to write it out:
File thefile = new File(outfile);
FileOutputStream fout = new FileOutputStream(thefile);
ObjectOutputStream oos = new ObjectOutputStream(fout);
oos.writeObject(vectorDB);//vectorDB is the arraylist mentioned
above.
oos.close();
fout.close();
With JBuilder personal 9, P4-2.2, 512M memory PC, with parameter of
"-Xmx512m", the above code will get out of memory java error and quit.
I noticed from WindowsXP's task manager, the system had a highpeak
memory
consume of > 900M (virtual of course). (CPU is also near 100% usage
for that)
So any idea of it? Why it is so slow and memory consuming for such a
35M data?
And any way to deal with it?
Thanks a lot.
Anyone know how to write/read objects to/from file faster than Java's
writeObject?
My program needs to write a ArrayList to file, which I found is very
very
slow and memory consumming using writeObject.
The arraylist is about 5000 size, each item of it is another arraylist
of about 3500 size, and each item of that is a Float. (So it is a
nested arraylist, with inner most object Float)
So I would expect the size of it should be around 5000*3500*2/1000000
= 35M byte, plus overhead of class/object.
However, I found when I try to use this code to write it out:
File thefile = new File(outfile);
FileOutputStream fout = new FileOutputStream(thefile);
ObjectOutputStream oos = new ObjectOutputStream(fout);
oos.writeObject(vectorDB);//vectorDB is the arraylist mentioned
above.
oos.close();
fout.close();
With JBuilder personal 9, P4-2.2, 512M memory PC, with parameter of
"-Xmx512m", the above code will get out of memory java error and quit.
I noticed from WindowsXP's task manager, the system had a highpeak
memory
consume of > 900M (virtual of course). (CPU is also near 100% usage
for that)
So any idea of it? Why it is so slow and memory consuming for such a
35M data?
And any way to deal with it?
Thanks a lot.