> Yes, that's the decision. But here I'm loading a huge
> matrix again in a memory. Is it any way to get the
> particular value directly from a file?
Generally it is relatively slow and inefficient to pick particular values from a file. HDs are good at getting to a sector and blasting lots of data
Anyway, another suggestion about storing matrix data, which I actually used is to serialize it to a file. If you've got a double[] or a double[][] it's a snap to serialize and deserialize this type of information
Although a database is probably the best idea, there are things you can do when you store the data in a file to make it relatively quick to access individual pieces of data.
Store the data in fixed length format so that you can calculate the starting byte of any piece of information and read it using RandomAccessFile.
Example:
Matrix:
1 1 30 4
2 20 800 1
1 2 3 4
Store in file:
0001000100300004
0002002008000001
0001000200030004
Now to get the data in the 2nd row 4th element (1):
starting byte = ((row ?1) * 16) + ((column ?1) * 4)
((2 ?1) * 16) + ((4 - 1) * 4)
16 + 13 = 29
If you actually have newline characters in the file then you will need to adjust for them also but you should get the idea.
Also, if your data is numeric then you do not need to store the data as string representations of numbers; you can store the actual bytes that make up the int, long, etc.
And if you want to get really fancy you could create indexes to different elements...wait, I think they have a name for that already : )
Message was edited by:
jbish
You haven't stated what you mean by a huge matrix. How big is huge? What does the matrix contain, can the elements be represented using the primitive types of Java? You say that you need to extract some values from it--are the values related in some way, are they close to each other?
Can the matrix fit on a hard drive without compression? If so and if you really have a lot of data, using a memory mapped file can be one solution.
If you have more than one big matrix that can fit in the computer's memory but you might have problems with fitting them all on the disk, you can treat them as images and compress them.