473,320 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

mmap in C++ vs. Java



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.

Feb 27 '07 #1
2 4908
be**********@gmail.com wrote:
>
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-lit...t.html#faq-5.9 for a
list of suggested newgroups.
Feb 27 '07 #2

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

Mar 2 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Hao Xu | last post by:
Hi everyone! I found that if you want to write to the memory got by mmap(), you have to get the file descriptor for mmap() in O_RDWR mode. If you got the file descriptor in O_WRONLY mode, then...
4
by: Fabiano Sidler | last post by:
Hi folks! I created an mmap object like so: --- snip --- from mmap import mmap,MAP_ANONYMOUS,MAP_PRIVATE fl = file('/dev/zero','rw') mm = mmap(fl.fileno(), 1, MAP_PRIVATE|MAP_ANONYMOUS) ---...
2
by: beejisbrigit | last post by:
Hi there, I was wondering if anyone had experience with File I/O in Java vs. C/C+ + using mmap(), and knew if the performance was better in one that the other, or more or less negligible. My...
1
by: James T. Dennis | last post by:
I've been thinking about the Python mmap module quite a bit during the last couple of days. Sadly most of it has just been thinking ... and reading pages from Google searches ... and very little...
1
by: koara | last post by:
Hello all, i am using the mmap module (python2.4) to access contents of a file. My question regards the relative performance of mmap.seek() vs mmap.tell(). I have a generator that returns...
2
by: Neal Becker | last post by:
On linux, I don't understand why: f = open ('/dev/eos', 'rw') m = mmap.mmap(f.fileno(), 1000000, prot=mmap.PROT_READ|mmap.PROT_WRITE, flags=mmap.MAP_SHARED) gives 'permission denied', but...
0
by: Kris Kennaway | last post by:
If I do the following: def mmap_search(f, string): fh = file(f) mm = mmap.mmap(fh.fileno(), 0, mmap.MAP_SHARED, mmap.PROT_READ) return mm.find(string) def mmap_is_in(f, string): fh =...
0
by: Gabriel Genellina | last post by:
En Thu, 29 May 2008 19:17:05 -0300, Kris Kennaway <kris@FreeBSD.org> escribió: Looks like you should define the sq_contains member in mmap_as_sequence, and the type should have the...
1
by: magnus.lycka | last post by:
Does anyone recognize this little Python crasher? I'll file a bug report unless someone notices it as an already documented bug. I found some open mmap bugs, but it wasn't obvious to me that...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.