mmap in C++ vs. Java

B

beejisbrigit

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.
 
R

red floyd

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.
This is OT in comp.lang.c++. The Standard does not define mmap().
Please ask in a newsgroup dedicated to your platform. See FAQ 5.9
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.9 for a
list of suggested newgroups.
 
P

Peter

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.
 

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

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top