mmap in C++ vs. Java

Discussion in 'C++' started by beejisbrigit@gmail.com, Feb 27, 2007.

  1. Guest

    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, 2007
    #1
    1. Advertising

  2. red floyd Guest

    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-lite/how-to-post.html#faq-5.9 for a
    list of suggested newgroups.
     
    red floyd, Feb 27, 2007
    #2
    1. Advertising

  3. Peter Guest

    <> wrote in message
    news:...
    >
    >
    > 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.
     
    Peter, Mar 2, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim Mays

    windows equiv to mmap()

    Jim Mays, Oct 23, 2003, in forum: C++
    Replies:
    2
    Views:
    861
    Jim Mays
    Oct 23, 2003
  2. Marco Cassiani

    mmap iterator validity

    Marco Cassiani, Mar 24, 2005, in forum: C++
    Replies:
    1
    Views:
    429
    Victor Bazarov
    Mar 24, 2005
  3. junky_fellow

    mmap vs read/write

    junky_fellow, Feb 25, 2004, in forum: C Programming
    Replies:
    3
    Views:
    903
    Derk Gwen
    Feb 25, 2004
  4. Parzival
    Replies:
    1
    Views:
    320
    Jeff Epler
    Nov 8, 2003
  5. mmap() in C/C++ vs. Java

    , Feb 27, 2007, in forum: C Programming
    Replies:
    2
    Views:
    735
    santosh
    Feb 28, 2007
Loading...

Share This Page