473,769 Members | 4,985 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4928
be**********@gm ail.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**********@g mail.comwrote in message
news:11******** **************@ v33g2000cwv.goo glegroups.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
3539
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 writing to the memory got by mmap() will lead to segmentation fault. Anyone knows why? Is this a rule or a bug? What if I just want to write to the file and nothing else?
4
3707
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) --- snap --- Now, when I try to resize mm to 10 byte
2
2777
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 instinct would say C/C++ is faster, but Java has made some improvements with its FileChannel class.
1
5468
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 of it as been coding. Mostly it's just academic curiosity (I might be teaching an "overview of programming" class in a few months, and I'd use Python for most of the practical examples to cover a broad range of programming topics, including the...
1
2692
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 stuff from the file, piece by piece. Since other things may happen to the mmap object in between consecutive next() calls (such as another iterator's next()), i have to store the file position before yield and restore it afterwards by means of tell()...
2
4636
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 this c++ code works: #include <sys/mman.h> #include <fcntl.h>
0
1148
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 = file(f)
0
1121
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 Py_TPFLAGS_HAVE_SEQUENCE_IN flag set (all in mmapmodule.c) -- Gabriel Genellina
1
1679
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 this problem was one of those... Python 2.5.2 (r252:60911, Apr 21 2008, 11:12:42) on linux2 Type "help", "copyright", "credits" or "license" for more information. Segmenteringsfel (core dumped)
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9994
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8870
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3958
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.