<be**********@gmail.comwrote in message
news:11**********************@v33g2000cwv.googlegr oups.com...
>
Hi there,
I was wondering if anyone had experience with File I/O in Java vs. C++
using mmap(),
and knew if the performance was better in one that the other, or more
or less negligible.
My instinct would say C++ is faster, but Java has made some
improvements with its
FileChannel class.
The situation is that a 1GB is to be loaded into memory and indexed as
the user needed.
thanks!
brigit.
If you want to use mmap just as a replace for the FileIO-Read system call
you may not get better performance
(comparing FileIORead with mmap/memcpy).
But if you are able to mmap your objects directly into memory without any
need of constructing/linking them,
then you would certainly get better performance with mmap() vs. the matching
FileIO-Read.
But this is not an easy task to do.
Depending what you want to write/read to/from disk you may have to write
your own heap manager.
Also if you want to be able to keep multiple files open at the same time
you may not be able to mmap them at the same address they occupied during
writing.
Also if you intend to keep the entire file in memory you need to be aware of
the limits of your system.
Also consider this if you want to keep multiple files open.
Also consider portability of your files from one type of system to the
other.
If this is an issue seralizing these files may be the better option.
Writing via mmaped files opens up an fully new set of problems.
If you're writing into a spares file you may end up with a signal SIGSEGV or
SIGBUS on UNIX systems and
with a structed exception on Windows -- the structured exception is easier
to convert into something useful than the signal.
So on UNIXs you may want to consider to allocate the entire file before
writing via mmap to make certain that you don't end up with a signal.