Main memory store

A

Alex

What's the most efficient way (in memory and execution time) of storing a
file in Main Memory for i) sequential and ii) non-sequential access in Java?
Please provide explanations where possible.


Thanks.
 
M

Marco Schmidt

Alex:
What's the most efficient way (in memory and execution time) of storing a
file in Main Memory for i) sequential and ii) non-sequential access in Java?

If you store a complete file in main memory, you already have full
sequential access. Otherwise, reading line by line (or filling a
buffer with characters sequentially) is more memory-friendly.

If this is not a homework question but a real-world problem, maybe you
can describe what you are trying to accomplish.

Regards,
Marco
 
M

Marco Schmidt

Alex:
I' m just doing research on encryption algorithms as part of a University
project and may need to access files (or at least parts of files)
non-sequentially. I'm more interested in knowing the answer to my question
in regard to the Java API & architecture.

For random access, use java.io.RandomAccessFile. With seek you go to
a certain offset, then use read or readFully to fill a byte array
(which you will probably need for encrypting data).

Since Java 1.4 there is the java.nio package which lets you map parts
of a file into memory. This may be faster in some cases.

Regards,
Marco
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top