:
:Dag-Erling Smorgrav <[EMAIL PROTECTED]> writes:
:> Remy Nonnenmacher <[EMAIL PROTECTED]> writes:
:> > Well, I may think using this solution if it remains portable between
:> > Unixes.
:> It's perfectly portable, with one small variation - on BSD systems,
:> you pass -1 instead of a file descriptor, while on SysV systems, you
:> pass a descriptor to /dev/zero (or was it /dev/null?)
:
:FWIW, I just did some tests - mmap()'ing /dev/zero works on FreeBSD as
:well, and mapping the same fd multiple times gives you separate areas,
:so you don't need a new fd for each.
:
:DES
:-- 
:Dag-Erling Smorgrav - [EMAIL PROTECTED]

    There are three ways to use mmap() to allocate memory:

    #1  MAP_ANON, when supported, should be used.

    #2  /dev/zero, when supported, should be used (tends to be more portable
        then MAP_ANON).

    #3  Create a temporary file, hold the descriptor, remove() the file,
        ftruncate() to the proper length, then mmap using MAP_PRIVATE. And
        then you can close the descriptor.  This actually takes up *NO*
        filesystem space, since it's a private map.

        You can also keep the descriptor around and allocate/free chunks
        using mmap()/munmap() out of it.  Just remember that you have to
        ftruncate() the file to be big enough to 'hold' your mmap ranges.

        This tends to be the most portable.

    Which of the three one uses depends on the OS.

                                        -Matt



To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to