Re: Memory mapping: MAP_PRIVATE and msync()

Liste des GroupesRevenir à l c 
Sujet : Re: Memory mapping: MAP_PRIVATE and msync()
De : bc (at) *nospam* freeuk.com (bart)
Groupes : comp.lang.c
Date : 08. Apr 2024, 13:14:30
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <uv0jik$3f285$1@dont-email.me>
References : 1 2 3
User-Agent : Mozilla Thunderbird
On 08/04/2024 02:50, Lawrence D'Oliveiro wrote:
On Sun, 07 Apr 24 15:18:47 +0000, pehache wrote:
 
void* p2 = mmap( NULL
                    , n
                    , PROT_READ | PROT_WRITE
                    , MAP_SHARED | MAP_NORESERVE
                    , fd
                    , 0 );
 Not easy to remember what the arguments mean. Try this:
      void * p2 = mmap
       (
         /*addr =*/ NULL,
         /*length =*/ n,
         /*prot =*/ PROT_READ | PROT_WRITE,
         /*flags =*/ MAP_SHARED | MAP_NORESERVE,
         /*fd =*/ fd,
         /*offset =*/ 0
       );
That's great but, how did you manage to figure out the meanings and order of the parameters in order to be able to write those comments?
If you have 1000s of calls to such functions, will you have those comments plastered everwhere?
In a language with proper named/keyword arguments, you don't need to remember the order. You don't need to supply all the arguments (eg. addr and offset in your example can have defaults, possibly those sets of flags too).
If you get an argument name wrong, it will tell you. I suspect that if you wrote this by mistake:
           /*prot =*/ MAP_SHARED | MAP_NORESERVE,
           /*flags =*/ PROT_READ | PROT_WRITE,
it would not be detected.

Date Sujet#  Auteur
7 Apr 24 * Memory mapping: MAP_PRIVATE and msync()11pehache
7 Apr 24 +* Re: Memory mapping: MAP_PRIVATE and msync()6pehache
7 Apr 24 i+- Re: Memory mapping: MAP_PRIVATE and msync()1pehache
8 Apr 24 i`* Re: Memory mapping: MAP_PRIVATE and msync()4Lawrence D'Oliveiro
8 Apr 24 i +- Re: Memory mapping: MAP_PRIVATE and msync()1Kaz Kylheku
8 Apr 24 i `* Re: Memory mapping: MAP_PRIVATE and msync()2bart
9 Apr 24 i  `- Re: Memory mapping: MAP_PRIVATE and msync()1Lawrence D'Oliveiro
7 Apr 24 `* Re: Memory mapping: MAP_PRIVATE and msync()4Lew Pitcher
7 Apr 24  `* Re: Memory mapping: MAP_PRIVATE and msync()3pehache
8 Apr 24   `* Re: Memory mapping: MAP_PRIVATE and msync()2pehache
8 Apr 24    `- fu2 is fne (Was: Memory mapping: =?UTF-8?Q?MAP=5FPRIVATE=20and=20msync=28=29?=)1Kenny McCormack

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal