Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Systems programmers are the high priests of a low cult. -- R. S. Barton


devel / comp.lang.c / Re: Memory mapping: MAP_PRIVATE and msync()

SubjectAuthor
* Memory mapping: MAP_PRIVATE and msync()pehache
+* Re: Memory mapping: MAP_PRIVATE and msync()pehache
|+- Re: Memory mapping: MAP_PRIVATE and msync()pehache
|`* Re: Memory mapping: MAP_PRIVATE and msync()Lawrence D'Oliveiro
| +- Re: Memory mapping: MAP_PRIVATE and msync()Kaz Kylheku
| `* Re: Memory mapping: MAP_PRIVATE and msync()bart
|  `- Re: Memory mapping: MAP_PRIVATE and msync()Lawrence D'Oliveiro
`* Re: Memory mapping: MAP_PRIVATE and msync()Lew Pitcher
 `* Re: Memory mapping: MAP_PRIVATE and msync()pehache
  `* Re: Memory mapping: MAP_PRIVATE and msync()pehache
   `- fu2 is fne (Was: Memory mapping: MAP_PRIVATE and msync())Kenny McCormack

1
Memory mapping: MAP_PRIVATE and msync()

<osGzrqwQ8DBTJ8mCFoPEiv6Pn0M@jntp>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34963&group=comp.lang.c#34963

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.niel.me!pasdenom.info!from-devjntp
Message-ID: <osGzrqwQ8DBTJ8mCFoPEiv6Pn0M@jntp>
JNTP-Route: news2.nemoweb.net
JNTP-DataType: Article
Subject: Memory mapping: MAP_PRIVATE and msync()
Newsgroups: comp.lang.c
JNTP-HashClient: mDaFF4rrTDVBcTjIEyulwvhjTkw
JNTP-ThreadID: Xt4PvXwVS7RUVBYIv4ru98146Os
JNTP-Uri: http://news2.nemoweb.net/?DataID=osGzrqwQ8DBTJ8mCFoPEiv6Pn0M@jntp
User-Agent: Nemo/0.999a
JNTP-OriginServer: news2.nemoweb.net
Date: Sun, 07 Apr 24 13:34:43 +0000
Organization: Nemoweb
JNTP-Browser: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:109.0) Gecko/20100101 Firefox/115.0
Injection-Info: news2.nemoweb.net; posting-host="516ee13c1e79fa65aedf115a32aee346f9289ca9"; logging-data="2024-04-07T13:34:43Z/8808721"; posting-account="44@news2.nemoweb.net"; mail-complaints-to="julien.arlandis@gmail.com"
JNTP-ProtocolVersion: 0.21.1
JNTP-Server: PhpNemoServer/0.94.5
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-JNTP-JsonNewsGateway: 0.96
From: pehach...@gmail.com (pehache)
 by: pehache - Sun, 7 Apr 2024 13:34 UTC

Hello,

When memory mapping a file with the MAP_PRIVATE flag, the modifications
(writes) only exist in memory and are not written back to the file.

According to the man pages, calling msync (3) on a such a mapping does NOT
writes the changes back:

"When the msync() function is called on MAP_PRIVATE mappings, any modified
data shall not be written to the underlying object and shall not cause
such data to be made visible to other processes"
https://linux.die.net/man/3/msync

So: is there a way to write the changes back to the file?

An obvious application is:
- mapping the file with MAP_PRIVATE
- make some modifications in memory only (fast) while keeping the original
version on disk (safe)
- at some point (when the user decides, and once the consistency of the
changes have been verified) writing the modifications to the disk

I'm pretty sure it exists some way or another, but I don't know how.

Re: Memory mapping: MAP_PRIVATE and msync()

<qmtiixDX3flrgimP-RUFSW_hf7o@jntp>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34964&group=comp.lang.c#34964

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.niel.me!pasdenom.info!from-devjntp
Message-ID: <qmtiixDX3flrgimP-RUFSW_hf7o@jntp>
JNTP-Route: news2.nemoweb.net
JNTP-DataType: Article
Subject: Re: Memory mapping: MAP_PRIVATE and msync()
References: <osGzrqwQ8DBTJ8mCFoPEiv6Pn0M@jntp>
Newsgroups: comp.lang.c
JNTP-HashClient: pFZhrOmu9lspfZaOqZgK_uC6638
JNTP-ThreadID: Xt4PvXwVS7RUVBYIv4ru98146Os
JNTP-ReferenceUserID: 44@news2.nemoweb.net
JNTP-Uri: http://news2.nemoweb.net/?DataID=qmtiixDX3flrgimP-RUFSW_hf7o@jntp
User-Agent: Nemo/0.999a
JNTP-OriginServer: news2.nemoweb.net
Date: Sun, 07 Apr 24 15:18:47 +0000
Organization: Nemoweb
JNTP-Browser: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:109.0) Gecko/20100101 Firefox/115.0
Injection-Info: news2.nemoweb.net; posting-host="516ee13c1e79fa65aedf115a32aee346f9289ca9"; logging-data="2024-04-07T15:18:47Z/8808843"; posting-account="44@news2.nemoweb.net"; mail-complaints-to="julien.arlandis@gmail.com"
JNTP-ProtocolVersion: 0.21.1
JNTP-Server: PhpNemoServer/0.94.5
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-JNTP-JsonNewsGateway: 0.96
From: pehach...@gmail.com (pehache)
 by: pehache - Sun, 7 Apr 2024 15:18 UTC

Le 07/04/2024 à 15:34, pehache a écrit :
> Hello,
>
> When memory mapping a file with the MAP_PRIVATE flag, the modifications (writes)
> only exist in memory and are not written back to the file.
>
> According to the man pages, calling msync (3) on a such a mapping does NOT
> writes the changes back:
>
> "When the msync() function is called on MAP_PRIVATE mappings, any modified data
> shall not be written to the underlying object and shall not cause such data to be
> made visible to other processes"
> https://linux.die.net/man/3/msync
>
> So: is there a way to write the changes back to the file?
>
> An obvious application is:
> - mapping the file with MAP_PRIVATE
> - make some modifications in memory only (fast) while keeping the original
> version on disk (safe)
> - at some point (when the user decides, and once the consistency of the changes
> have been verified) writing the modifications to the disk
>
> I'm pretty sure it exists some way or another, but I don't know how.

At the moment what I'm doing is something like:

========================================
fd = open("aaa",O_RDWR);
p = mmap ( NULL
, n
, PROT_READ | PROT_WRITE
, MAP_PRIVATE | MAP_NORESERVE
, fd
, 0 );

// writing to p; the changes exist only in memory

void* p2 = mmap( NULL
, n
, PROT_READ | PROT_WRITE
, MAP_SHARED | MAP_NORESERVE
, fd
, 0 );

memcpy(p2,p,n); // copying everything from p to p2
msync(p2,n);

// unmap/remap p so it's ready for new changes
munmap(p,n);
p = mmap ( NULL
, n
, PROT_READ | PROT_WRITE
, MAP_PRIVATE | MAP_NORESERVE
, fd
, 0 );

========================================

This works, but:

- the whole content is copied, not only the changed content
- is this code legal? Is there any potential conflict between the 2
mapping, with an undefined behavior?

Re: Memory mapping: MAP_PRIVATE and msync()

<uuufai$2rdn1$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34965&group=comp.lang.c#34965

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.lang.c
Subject: Re: Memory mapping: MAP_PRIVATE and msync()
Date: Sun, 7 Apr 2024 15:49:38 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <uuufai$2rdn1$1@dont-email.me>
References: <osGzrqwQ8DBTJ8mCFoPEiv6Pn0M@jntp>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 07 Apr 2024 15:49:38 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="b3170d528ee0ea357302420461f28724";
logging-data="2995937"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18x0MUmCeefX+xabecuy96cwUW3Asc5dNQ="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:2mZdLyBveFjvKSlVAJc7NnIiTNs=
 by: Lew Pitcher - Sun, 7 Apr 2024 15:49 UTC

On Sun, 07 Apr 2024 13:34:43 +0000, pehache wrote:

> Hello,

Hi, pehache

> When memory mapping a file with the MAP_PRIVATE flag, the modifications
> (writes) only exist in memory and are not written back to the file.
[snip]
> So: is there a way to write the changes back to the file?
[snip]

The comp.unix.programmer newsgroup will be of better help for this sort
of question (it's not really on-topic for comp.lang.c).

But, of the top of my head; with my limited understanding of the unix
mmap() kernel call, the only ways to "write the changes" are to either
1) mmap(MAP_SHARED) and modify the mapped area, or
2) write() the mapped area back to the file.

But, as I said, comp.unix.programmer will be of better help.

--
Lew Pitcher
"In Skills We Trust"

Re: Memory mapping: MAP_PRIVATE and msync()

<zg5bFPBPOWrwfU5oe0Ftvee3OqQ@jntp>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34967&group=comp.lang.c#34967

  copy link   Newsgroups: comp.lang.c comp.unix.programmer
Followup: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.niel.me!pasdenom.info!from-devjntp
Message-ID: <zg5bFPBPOWrwfU5oe0Ftvee3OqQ@jntp>
JNTP-Route: news2.nemoweb.net
JNTP-DataType: Article
Subject: Re: Memory mapping: MAP_PRIVATE and msync()
References: <osGzrqwQ8DBTJ8mCFoPEiv6Pn0M@jntp> <qmtiixDX3flrgimP-RUFSW_hf7o@jntp>
Newsgroups: comp.lang.c,comp.unix.programmer
Followup-To: comp.unix.programmer
JNTP-HashClient: DhiH4rCtsa2DqAZvwt6pm0akAyw
JNTP-ThreadID: Xt4PvXwVS7RUVBYIv4ru98146Os
JNTP-ReferenceUserID: 44@news2.nemoweb.net
JNTP-Uri: http://news2.nemoweb.net/?DataID=zg5bFPBPOWrwfU5oe0Ftvee3OqQ@jntp
User-Agent: Nemo/0.999a
JNTP-OriginServer: news2.nemoweb.net
Date: Sun, 07 Apr 24 19:04:27 +0000
Organization: Nemoweb
JNTP-Browser: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:109.0) Gecko/20100101 Firefox/115.0
Injection-Info: news2.nemoweb.net; posting-host="516ee13c1e79fa65aedf115a32aee346f9289ca9"; logging-data="2024-04-07T19:04:27Z/8809090"; posting-account="44@news2.nemoweb.net"; mail-complaints-to="julien.arlandis@gmail.com"
JNTP-ProtocolVersion: 0.21.1
JNTP-Server: PhpNemoServer/0.94.5
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-JNTP-JsonNewsGateway: 0.96
From: pehach...@gmail.com (pehache)
 by: pehache - Sun, 7 Apr 2024 19:04 UTC

As advised, I'm copying this post here

Le 07/04/2024 à 17:18, pehache a écrit :
> Le 07/04/2024 à 15:34, pehache a écrit :
>> Hello,
>>
>> When memory mapping a file with the MAP_PRIVATE flag, the modifications (writes)
>> only exist in memory and are not written back to the file.
>>
>> According to the man pages, calling msync (3) on a such a mapping does NOT
>> writes the changes back:
>>
>> "When the msync() function is called on MAP_PRIVATE mappings, any modified data
>> shall not be written to the underlying object and shall not cause such data to be
>> made visible to other processes"
>> https://linux.die.net/man/3/msync
>>
>> So: is there a way to write the changes back to the file?
>>
>> An obvious application is:
>> - mapping the file with MAP_PRIVATE
>> - make some modifications in memory only (fast) while keeping the original
>> version on disk (safe)
>> - at some point (when the user decides, and once the consistency of the changes
>> have been verified) writing the modifications to the disk
>>
>> I'm pretty sure it exists some way or another, but I don't know how.
>
> At the moment what I'm doing is something like:
>
> ========================================
> fd = open("aaa",O_RDWR);
> p = mmap ( NULL
> , n
> , PROT_READ | PROT_WRITE
> , MAP_PRIVATE | MAP_NORESERVE
> , fd
> , 0 );
>
> // writing to p; the changes exist only in memory
>
> void* p2 = mmap( NULL
> , n
> , PROT_READ | PROT_WRITE
> , MAP_SHARED | MAP_NORESERVE
> , fd
> , 0 );
>
> memcpy(p2,p,n); // copying everything from p to p2
> msync(p2,n);
>
> // unmap/remap p so it's ready for new changes
> munmap(p,n);
> p = mmap ( NULL
> , n
> , PROT_READ | PROT_WRITE
> , MAP_PRIVATE | MAP_NORESERVE
> , fd
> , 0 );
>
> ========================================
>
> This works, but:
>
> - the whole content is copied, not only the changed content
> - is this code legal? Is there any potential conflict between the 2 mapping,
> with an undefined behavior?

Re: Memory mapping: MAP_PRIVATE and msync()

<3SRfxOJmmxW4o_baSf1Air4dZWk@jntp>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34968&group=comp.lang.c#34968

  copy link   Newsgroups: comp.lang.c comp.unix.programmer
Followup: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.niel.me!pasdenom.info!from-devjntp
Message-ID: <3SRfxOJmmxW4o_baSf1Air4dZWk@jntp>
JNTP-Route: news2.nemoweb.net
JNTP-DataType: Article
Subject: Re: Memory mapping: MAP_PRIVATE and msync()
References: <osGzrqwQ8DBTJ8mCFoPEiv6Pn0M@jntp> <uuufai$2rdn1$1@dont-email.me>
Newsgroups: comp.lang.c,comp.unix.programmer
Followup-To: comp.unix.programmer
JNTP-HashClient: IhEw_Vx2Ze5kfw7O-zQ_M0nXgpI
JNTP-ThreadID: Xt4PvXwVS7RUVBYIv4ru98146Os
JNTP-Uri: http://news2.nemoweb.net/?DataID=3SRfxOJmmxW4o_baSf1Air4dZWk@jntp
User-Agent: Nemo/0.999a
JNTP-OriginServer: news2.nemoweb.net
Date: Sun, 07 Apr 24 19:09:17 +0000
Organization: Nemoweb
JNTP-Browser: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:109.0) Gecko/20100101 Firefox/115.0
Injection-Info: news2.nemoweb.net; posting-host="516ee13c1e79fa65aedf115a32aee346f9289ca9"; logging-data="2024-04-07T19:09:17Z/8809100"; posting-account="44@news2.nemoweb.net"; mail-complaints-to="julien.arlandis@gmail.com"
JNTP-ProtocolVersion: 0.21.1
JNTP-Server: PhpNemoServer/0.94.5
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-JNTP-JsonNewsGateway: 0.96
From: pehach...@gmail.com (pehache)
 by: pehache - Sun, 7 Apr 2024 19:09 UTC

Le 07/04/2024 à 15:49, Lew Pitcher a écrit :
> On Sun, 07 Apr 2024 13:34:43 +0000, pehache wrote:
>
>> Hello,
>
> Hi, pehache
>
>> When memory mapping a file with the MAP_PRIVATE flag, the modifications
>> (writes) only exist in memory and are not written back to the file.
> [snip]
>> So: is there a way to write the changes back to the file?
> [snip]
>
> The comp.unix.programmer newsgroup will be of better help for this sort
> of question (it's not really on-topic for comp.lang.c).
>
> But, of the top of my head; with my limited understanding of the unix
> mmap() kernel call, the only ways to "write the changes" are to either
> 1) mmap(MAP_SHARED) and modify the mapped area, or
> 2) write() the mapped area back to the file.

I'm currenly using the first option in my code. Either way, the whole
mapped area is written back, even if there were only a few changes. I was
hoping there could be another way to wrtite back only the modified pages.

> But, as I said, comp.unix.programmer will be of better help.

fu2

Re: Memory mapping: MAP_PRIVATE and msync()

<uuvigf$340q8$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34971&group=comp.lang.c#34971

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo...@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.c
Subject: Re: Memory mapping: MAP_PRIVATE and msync()
Date: Mon, 8 Apr 2024 01:50:07 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <uuvigf$340q8$1@dont-email.me>
References: <osGzrqwQ8DBTJ8mCFoPEiv6Pn0M@jntp>
<qmtiixDX3flrgimP-RUFSW_hf7o@jntp>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 08 Apr 2024 01:50:07 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="ba48ee83c2dfe27d1f58abbb170b1e26";
logging-data="3277640"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18O1eM16pjQuyKOM5gHANAD"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:2ekvutD76LscuGqy7V+pL61HlII=
 by: Lawrence D'Oliv - Mon, 8 Apr 2024 01:50 UTC

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
);

Re: Memory mapping: MAP_PRIVATE and msync()

<20240407200220.887@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34972&group=comp.lang.c#34972

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 643-408-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Memory mapping: MAP_PRIVATE and msync()
Date: Mon, 8 Apr 2024 03:06:26 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 45
Message-ID: <20240407200220.887@kylheku.com>
References: <osGzrqwQ8DBTJ8mCFoPEiv6Pn0M@jntp>
<qmtiixDX3flrgimP-RUFSW_hf7o@jntp> <uuvigf$340q8$1@dont-email.me>
Injection-Date: Mon, 08 Apr 2024 03:06:26 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="dae03b64fb58948204ae1ff12d0cc886";
logging-data="3431633"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19eovqi649Np7m1vM91NICvQnKI0FAxdRU="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:sejxbmPnqU3YBM0kwHDPOBN5QF8=
 by: Kaz Kylheku - Mon, 8 Apr 2024 03:06 UTC

On 2024-04-08, Lawrence D'Oliveiro <ldo@nz.invalid> 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:

Nobody is going to follow your grotesque, poorly considered coding
conventions.

>
> void * p2 = mmap
> (
> /*addr =*/ NULL,
^^^^ ^^^^ a null pointer is some kind of "addr"

> /*length =*/ n,
> /*prot =*/ PROT_READ | PROT_WRITE,
^^^^ ^^^^
| |
`---------|---- You know this
`---- from this.

> /*flags =*/ MAP_SHARED | MAP_NORESERVE,
^^^^
Tells you nothing. You know that preprocessor constants
combined together with | are "flags".

> /*fd =*/ fd,
^^ ^^
identical, tells you nothing.

> /*offset =*/ 0
> );

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: Memory mapping: MAP_PRIVATE and msync()

<uv0jik$3f285$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34973&group=comp.lang.c#34973

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (bart)
Newsgroups: comp.lang.c
Subject: Re: Memory mapping: MAP_PRIVATE and msync()
Date: Mon, 8 Apr 2024 12:14:30 +0100
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <uv0jik$3f285$1@dont-email.me>
References: <osGzrqwQ8DBTJ8mCFoPEiv6Pn0M@jntp>
<qmtiixDX3flrgimP-RUFSW_hf7o@jntp> <uuvigf$340q8$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 08 Apr 2024 11:14:29 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="21332d40c8b82da56a0d1677ea5ecf5e";
logging-data="3639557"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+LnO4xE49A6kB0wbP7n8Kj"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:VdYymsbYGs3y+zis+xeurPeqmOI=
Content-Language: en-GB
In-Reply-To: <uuvigf$340q8$1@dont-email.me>
 by: bart - Mon, 8 Apr 2024 11:14 UTC

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.

Re: Memory mapping: MAP_PRIVATE and msync()

<PgZyW9oCgOxERNyTFwXvTAzcfig@jntp>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34975&group=comp.lang.c#34975

  copy link   Newsgroups: comp.unix.programmer comp.lang.c
Followup: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.hispagatos.org!news.nntp4.net!pasdenom.info!from-devjntp
Message-ID: <PgZyW9oCgOxERNyTFwXvTAzcfig@jntp>
JNTP-Route: news2.nemoweb.net
JNTP-DataType: Article
Subject: Re: Memory mapping: MAP_PRIVATE and msync()
References: <osGzrqwQ8DBTJ8mCFoPEiv6Pn0M@jntp> <uuufai$2rdn1$1@dont-email.me> <3SRfxOJmmxW4o_baSf1Air4dZWk@jntp>
<uuvb5d$32kd4$1@dont-email.me> <871q7ghgww.fsf@nosuchdomain.example.com>
Newsgroups: comp.unix.programmer,comp.lang.c
Followup-To: comp.unix.programmer
JNTP-HashClient: tyIxevUCNkRmmQoYR22_cxN72mU
JNTP-ThreadID: Xt4PvXwVS7RUVBYIv4ru98146Os
JNTP-Uri: http://news2.nemoweb.net/?DataID=PgZyW9oCgOxERNyTFwXvTAzcfig@jntp
User-Agent: Nemo/0.999a
JNTP-OriginServer: news2.nemoweb.net
Date: Mon, 08 Apr 24 16:00:02 +0000
Organization: Nemoweb
JNTP-Browser: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0
Injection-Info: news2.nemoweb.net; posting-host="8c0d27be66314e02642b325213f4ebe9b2f8b48c"; logging-data="2024-04-08T16:00:02Z/8809955"; posting-account="44@news2.nemoweb.net"; mail-complaints-to="julien.arlandis@gmail.com"
JNTP-ProtocolVersion: 0.21.1
JNTP-Server: PhpNemoServer/0.94.5
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-JNTP-JsonNewsGateway: 0.96
From: pehach...@gmail.com (pehache)
 by: pehache - Mon, 8 Apr 2024 16:00 UTC

Le 07/04/2024 à 23:49, Keith Thompson a écrit :
> James Kuyper <jameskuyper@alumni.caltech.edu> writes:
>> On 4/7/24 15:09, pehache wrote:
>>> Le 07/04/2024 à 15:49, Lew Pitcher a écrit :
>> ...
>>>> But, as I said, comp.unix.programmer will be of better help.
>>>
>>> fu2
>>
>> Why does that advice annoy you? Why wouldn't you want to take your
>> question to the forum where people are best qualified to answer it?
>
> I believe "fu2" refers to this header line in the article you're
> replying to :
> Followup-To: comp.unix.programmer

That's correct.

>
> pehache: Apparently James thought "fu2" meant ... something else.

OK, sorry for the misunderstanding :( !

"fu2" is a routinely used abbreviation for "Followup-To" (and just that!)
on the fr.* hierarchy, and I thought it was kind of universal on all
hierarchies. Apparently it's not...

fu2 is fne (Was: Memory mapping: MAP_PRIVATE and msync())

<uv14sm$3hiq8$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34976&group=comp.lang.c#34976

  copy link   Newsgroups: comp.unix.programmer comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.programmer,comp.lang.c
Subject: fu2 is fne (Was: Memory mapping: MAP_PRIVATE and msync())
Date: Mon, 8 Apr 2024 16:09:58 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <uv14sm$3hiq8$1@news.xmission.com>
References: <osGzrqwQ8DBTJ8mCFoPEiv6Pn0M@jntp> <uuvb5d$32kd4$1@dont-email.me> <871q7ghgww.fsf@nosuchdomain.example.com> <PgZyW9oCgOxERNyTFwXvTAzcfig@jntp>
Injection-Date: Mon, 8 Apr 2024 16:09:58 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="3722056"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Mon, 8 Apr 2024 16:09 UTC

In article <PgZyW9oCgOxERNyTFwXvTAzcfig@jntp>,
pehache <pehache.7@gmail.com> wrote:
....
>OK, sorry for the misunderstanding :( !

Nothing to be sorry about.

>"fu2" is a routinely used abbreviation for "Followup-To" (and just that!)
>on the fr.* hierarchy, and I thought it was kind of universal on all
>hierarchies. Apparently it's not...

It is fine.

This poster (James whatever) has a long history of weirdly misunderstanding
things. I wouldn't worry about it.

--
Many people in the American South think that DJT is, and will be remembered
as, one of the best presidents in US history. They are absolutely correct.

He is currently at number 46 on the list. High praise, indeed!

Re: Memory mapping: MAP_PRIVATE and msync()

<uv271f$3r9k2$4@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=34979&group=comp.lang.c#34979

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo...@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.c
Subject: Re: Memory mapping: MAP_PRIVATE and msync()
Date: Tue, 9 Apr 2024 01:52:48 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <uv271f$3r9k2$4@dont-email.me>
References: <osGzrqwQ8DBTJ8mCFoPEiv6Pn0M@jntp>
<qmtiixDX3flrgimP-RUFSW_hf7o@jntp> <uuvigf$340q8$1@dont-email.me>
<uv0jik$3f285$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 09 Apr 2024 01:52:48 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="c62da5eaa27d15bf3b04834dfd3595c9";
logging-data="4040322"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18rDCfj++XVBupmliivd2ly"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:SBFU2FGAK+wo40MO/pLSy8tRBGo=
 by: Lawrence D'Oliv - Tue, 9 Apr 2024 01:52 UTC

On Mon, 8 Apr 2024 12:14:30 +0100, bart wrote:

> ... how did you manage to figure out the meanings and
> order of the parameters in order to be able to write those comments?

I read the docs.

> If you have 1000s of calls to such functions, will you have those
> comments plastered everwhere?

Yes.

> In a language with proper named/keyword arguments, you don't need to
> remember the order.

True. I take advantage of that--and defaults for omitted arguments--in
Python.

But there are people in this noisegroup who don’t like me mentioning that.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor