Questions about mmap()

Discussion in 'C Programming' started by Unknown Soldier, Apr 8, 2008.

  1. Hello,

    I have a couple queries about mmap() that ppl here might be able to help
    with.

    1. What's the best way to resize an mmap()d area when you've enlarged
    the file? Can you call mmap() again with the existing mapped location,
    or do you need to remap it from scratch?

    2. If I have a file descriptor returned by a call to socket(), can I
    used mmap() as an alterantive to read()? Will there be problems
    depending on whether the socket is blocking?

    Thanks.
     
    Unknown Soldier, Apr 8, 2008
    #1
    1. Advertising

  2. Unknown Soldier

    Flash Gordon Guest

    Unknown Soldier wrote, On 08/04/08 20:50:
    > Hello,
    >
    > I have a couple queries about mmap() that ppl here might be able to help
    > with.


    <snip>

    The people over on comp.unix.programmer are more likely to be able to
    provide quality help on this since I am guessing you are using the Unix
    mmap function. mmap is a system extension rather than being part of the
    C language as defined by the C standard.
    --
    Flash Gordon
     
    Flash Gordon, Apr 8, 2008
    #2
    1. Advertising

  3. On 8 Apr 2008 at 19:50, Unknown Soldier wrote:
    > Hello,
    >
    > I have a couple queries about mmap() that ppl here might be able to help
    > with.
    >
    > 1. What's the best way to resize an mmap()d area when you've enlarged
    > the file? Can you call mmap() again with the existing mapped location,
    > or do you need to remap it from scratch?


    There's no guarantee that the original mapping is contained in a large
    enough space in the process's virtual address space for the new mapping
    to fit, so you really need to unmap and the remap the whole thing.

    On Linux, there's an mremap function that takes care of this for you
    (it's analogous to realloc), but you should be aware that this function
    isn't in POSIX, so relying on it will make your program non-portable.

    > 2. If I have a file descriptor returned by a call to socket(), can I
    > used mmap() as an alterantive to read()? Will there be problems
    > depending on whether the socket is blocking?


    I don't think so - what would that even mean? It doesn't make sense.
     
    Antoninus Twink, Apr 8, 2008
    #3
  4. Unknown Soldier <> writes:
    > I have a couple queries about mmap() that ppl here might be able to
    > help with.

    [snip]

    Some people here might try, but you'll get better answers in
    comp.unix.programmer. The mmap() function is defined by POSIX, not by
    the C language standard.

    --
    Keith Thompson (The_Other_Keith) <>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Apr 8, 2008
    #4
  5. On 8 Apr 2008 at 20:18, Dann Corbit wrote:
    > "Dann Corbit" <> wrote in message
    >> I am curious about what you expect to gain by memory mapping a socket.

    >
    > I guess that there is a benefit:
    > Multiple outstanding I/O operations on a single file descriptor using
    > threads:
    > http://www.squid-cache.org/mail-archive/squid-dev/199805/0139.html


    That's an interesting (albeit bizarre) idea... as far as I can see,
    though, all the sample code on that page first mmaps a file, then
    read()s from a socket into the mmap'd area, rather than actually
    attempting to mmap the socket itself.
     
    Antoninus Twink, Apr 8, 2008
    #5
  6. Unknown Soldier

    ppl Guest

    Jack Klein wrote:

    > ppl doesn't participate in this group any more. We killed him and ate
    > his liver.
    >


    But... Why?
     
    ppl, Apr 9, 2008
    #6
    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:
    869
    Jim Mays
    Oct 23, 2003
  2. Marco Cassiani

    mmap iterator validity

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

    mmap vs read/write

    junky_fellow, Feb 25, 2004, in forum: C Programming
    Replies:
    3
    Views:
    919
    Derk Gwen
    Feb 25, 2004
  4. Parzival
    Replies:
    1
    Views:
    339
    Jeff Epler
    Nov 8, 2003
  5. Dan Jones

    raw string from mmap.read() possible?

    Dan Jones, Nov 9, 2003, in forum: Python
    Replies:
    1
    Views:
    337
    David M. Wilson
    Nov 9, 2003
Loading...

Share This Page