Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Pay no attention to the man behind the curtain." -- The Wizard Of Oz


devel / comp.lang.c / Dymamic arrays: memory management and naming

SubjectAuthor
* Dymamic arrays: memory management and namingAnton Shepelev
+- Re: Dymamic arrays: memory management and namingMalcolm McLean
+- Re: Dymamic arrays: memory management and namingKaz Kylheku
+- Re: Dymamic arrays: memory management and namingScott Lurndal
+* Re: Dymamic arrays: memory management and namingSpiros Bousbouras
|`* Re: Dymamic arrays: memory management and namingAnton Shepelev
| `- Re: Dymamic arrays: memory management and namingKaz Kylheku
+* Re: Dymamic arrays: memory management and namingTim Rentsch
|+- Re: Dymamic arrays: memory management and namingAnton Shepelev
|`- Re: Dymamic arrays: memory management and namingAnton Shepelev
`* Re: Dymamic arrays: memory management and namingTim Rentsch
 `* Re: Dymamic arrays: memory management and namingAnton Shepelev
  +- Re: Dymamic arrays: memory management and namingTim Rentsch
  `* Re: Dymamic arrays: memory management and namingTim Rentsch
   +* Re: Dymamic arrays: memory management and namingKeith Thompson
   |+- Re: Dymamic arrays: memory management and namingChris M. Thomasson
   |+* Re: Dymamic arrays: memory management and namingKaz Kylheku
   ||`* Re: Dymamic arrays: memory management and namingTim Rentsch
   || +* Re: Dymamic arrays: memory management and namingKeith Thompson
   || |`- Re: Dymamic arrays: memory management and namingTim Rentsch
   || `* Re: Dymamic arrays: memory management and namingKaz Kylheku
   ||  `* Re: Dymamic arrays: memory management and namingTim Rentsch
   ||   `- Re: Dymamic arrays: memory management and namingKaz Kylheku
   |`- Re: Dymamic arrays: memory management and namingTim Rentsch
   `* Re: Dymamic arrays: memory management and namingAnton Shepelev
    +- Re: Dymamic arrays: memory management and namingBlue-Maned_Hawk
    +- Re: Dymamic arrays: memory management and namingJames Kuyper
    +* Re: Dymamic arrays: memory management and namingSpiros Bousbouras
    |+* Re: Dymamic arrays: memory management and namingKaz Kylheku
    ||+* Re: Dymamic arrays: memory management and namingTim Rentsch
    |||`* Re: Dymamic arrays: memory management and namingKaz Kylheku
    ||| `- Re: Dymamic arrays: memory management and namingTim Rentsch
    ||`* Re: Dymamic arrays: memory management and namingKaz Kylheku
    || `* Re: Dymamic arrays: memory management and namingTim Rentsch
    ||  +* Re: Dymamic arrays: memory management and namingKaz Kylheku
    ||  |`- Re: Dymamic arrays: memory management and namingTim Rentsch
    ||  `* Re: Dymamic arrays: memory management and namingKeith Thompson
    ||   `* Re: Dymamic arrays: memory management and namingTim Rentsch
    ||    `* Re: Dymamic arrays: memory management and namingKeith Thompson
    ||     `- Re: Dymamic arrays: memory management and namingTim Rentsch
    |+- Re: Dymamic arrays: memory management and namingKaz Kylheku
    |+* Re: Dymamic arrays: memory management and namingJames Kuyper
    ||`* Re: Dymamic arrays: memory management and namingKaz Kylheku
    || `- Re: Dymamic arrays: memory management and namingJames Kuyper
    |`* Re: Dymamic arrays: memory management and namingPhil Carmody
    | `- Re: Dymamic arrays: memory management and namingSpiros Bousbouras
    `* Re: Dymamic arrays: memory management and namingTim Rentsch
     `* Re: Dymamic arrays: memory management and namingKaz Kylheku
      `* Re: Dymamic arrays: memory management and namingTim Rentsch
       +- Re: Dymamic arrays: memory management and namingKaz Kylheku
       `- Re: Dymamic arrays: memory management and namingKaz Kylheku

Pages:123
Dymamic arrays: memory management and naming

<20230909132336.99cdb303ad685bc1e40f92df@gmail.moc>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton....@gmail.moc (Anton Shepelev)
Newsgroups: comp.lang.c
Subject: Dymamic arrays: memory management and naming
Date: Sat, 9 Sep 2023 13:23:36 +0300
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <20230909132336.99cdb303ad685bc1e40f92df@gmail.moc>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="e2401a843d738dcce6359c697c7d4b64";
logging-data="49891"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19cEvan8XAv0rltzWU+Mh62i1D6REnIZ6g="
Cancel-Lock: sha1:1TqQPHz/VkjojRykkqs6zbTDeEg=
X-Newsreader: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
 by: Anton Shepelev - Sat, 9 Sep 2023 10:23 UTC

Hello, all

I have decided to publish my implementaton of dymanic arrays
that you helped me with back in 2018[1] (time rolls like a
steamroller). The initial version will have a single built-
in memory-management strategy, and I ask your opinion about
one based on a fixed Fibonacci progerssion, so that the
array size in bytes grows as: 1,2,3,5,8,13,... And of course
it may start with any Fibonacci number if required. The
purpose is to let the memory manager re-use the two previous
adjacent allocations for the next one without any gaps.

The fixed sizes help unify memory usage between different
dymamic arrays. Do you think it worth the effort, or is a
simple 1.5 growth factor relative to whatever the current
capacity the array has better on the whole, in that it has a
much higher ratio of efficiency to code complexity, for the
Fibonacci approach will require the storage of the previous
capacity and a lookup algorithm for cases when the
programmer sets the array length explicitly (so that a
request of 12 bytes results in a 13-byte allocation).

Another question is function names. The current ones use
the `da_' prefix:

void* da_new ( size_t elem_sz ); /* create an array */
void* da_newl ( size_t elem_sz, unsigned int len ); /* of specified length */
void* da_setlen( void * a , unsigned int len ); /* set the length */
int da_len ( void * a ); /* get the length */
void* da_add ( void * a , void * data_p ); /* add an element */
void* da_addemp( void * a , void ** elem_pp ); /* add an empty element */
/* ..and provide its address for writing */
void da_free ( void * a ); /* deallocate */

Do you think the `a_' prefix would incur a significant risk
of name collisions?
____________________
1. In two threads:
<20181117143819.43938ee34006bbcc1826bf0c@gmail.com>
<20181119022614.5cf93af72a29cb41cdc86910@gmail.com>

--
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments

Re: Dymamic arrays: memory management and naming

<d4f8fa0b-12ff-4efb-85f5-197c5d6d6c3cn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ac8:4553:0:b0:414:ce7b:6f7f with SMTP id z19-20020ac84553000000b00414ce7b6f7fmr213725qtn.1.1694256974149;
Sat, 09 Sep 2023 03:56:14 -0700 (PDT)
X-Received: by 2002:a05:6a00:80c:b0:68e:2c35:7cba with SMTP id
m12-20020a056a00080c00b0068e2c357cbamr1952079pfk.2.1694256973677; Sat, 09 Sep
2023 03:56:13 -0700 (PDT)
Path: i2pn2.org!i2pn.org!paganini.bofh.team!2.eu.feeder.erje.net!feeder.erje.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sat, 9 Sep 2023 03:56:13 -0700 (PDT)
In-Reply-To: <20230909132336.99cdb303ad685bc1e40f92df@gmail.moc>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:3183:56e0:5605:146;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:3183:56e0:5605:146
References: <20230909132336.99cdb303ad685bc1e40f92df@gmail.moc>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d4f8fa0b-12ff-4efb-85f5-197c5d6d6c3cn@googlegroups.com>
Subject: Re: Dymamic arrays: memory management and naming
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Sat, 09 Sep 2023 10:56:14 +0000
Content-Type: text/plain; charset="UTF-8"
 by: Malcolm McLean - Sat, 9 Sep 2023 10:56 UTC

On Saturday, 9 September 2023 at 11:23:51 UTC+1, Anton Shepelev wrote:
> Hello, all
>
> I have decided to publish my implementaton of dymanic arrays
> that you helped me with back in 2018[1] (time rolls like a
> steamroller). The initial version will have a single built-
> in memory-management strategy, and I ask your opinion about
> one based on a fixed Fibonacci progerssion, so that the
> array size in bytes grows as: 1,2,3,5,8,13,... And of course
> it may start with any Fibonacci number if required. The
> purpose is to let the memory manager re-use the two previous
> adjacent allocations for the next one without any gaps.
>
> The fixed sizes help unify memory usage between different
> dymamic arrays. Do you think it worth the effort, or is a
> simple 1.5 growth factor relative to whatever the current
> capacity the array has better on the whole, in that it has a
> much higher ratio of efficiency to code complexity, for the
> Fibonacci approach will require the storage of the previous
> capacity and a lookup algorithm for cases when the
> programmer sets the array length explicitly (so that a
> request of 12 bytes results in a 13-byte allocation).
>
> Another question is function names. The current ones use
> the `da_' prefix:
>
> void* da_new ( size_t elem_sz ); /* create an array */
> void* da_newl ( size_t elem_sz, unsigned int len ); /* of specified length */
> void* da_setlen( void * a , unsigned int len ); /* set the length */
> int da_len ( void * a ); /* get the length */
> void* da_add ( void * a , void * data_p ); /* add an element */
> void* da_addemp( void * a , void ** elem_pp ); /* add an empty element */
> /* ..and provide its address for writing */
> void da_free ( void * a ); /* deallocate */
>
> Do you think the `a_' prefix would incur a significant risk
> of name collisions?
> ____________________
> 1. In two threads:
> <20181117143819.4393...@gmail.com>
> <20181119022614.5cf9...@gmail.com>
>
I strongly suspect that array lengths have a statistical distribution such that
the Fibonacci sequence provides the best prediction of eventual length
given current length.
We know that 1.5 works reasonably well, and phi is 1.618, which isn't too
far off.
How you'd prove that I'm not sure.

Re: Dymamic arrays: memory management and naming

<20230909080252.880@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Dymamic arrays: memory management and naming
Date: Sat, 9 Sep 2023 15:06:15 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <20230909080252.880@kylheku.com>
References: <20230909132336.99cdb303ad685bc1e40f92df@gmail.moc>
Injection-Date: Sat, 9 Sep 2023 15:06:15 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="cbf43b42d7a4bc81e1a1f81e08c9fb9f";
logging-data="141594"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+YcIxsILfl0tn1jQpQj4GJw5sghiY7sWk="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:B21Xi/bpFJ+4kd4oTBYvUW7Ln5g=
 by: Kaz Kylheku - Sat, 9 Sep 2023 15:06 UTC

On 2023-09-09, Anton Shepelev <anton.txt@gmail.moc> wrote:
> Do you think the `a_' prefix would incur a significant risk
> of name collisions?

That risk is something that only becomes real when your library
is actually used. So I wouldn't worry about it, and concentrate
on getting the library used.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: Dymamic arrays: memory management and naming

<Ip0LM.1449507$GMN3.698219@fx16.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx16.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Dymamic arrays: memory management and naming
Newsgroups: comp.lang.c
References: <20230909132336.99cdb303ad685bc1e40f92df@gmail.moc>
Lines: 10
Message-ID: <Ip0LM.1449507$GMN3.698219@fx16.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Sat, 09 Sep 2023 15:44:40 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Sat, 09 Sep 2023 15:44:40 GMT
X-Received-Bytes: 806
 by: Scott Lurndal - Sat, 9 Sep 2023 15:44 UTC

Anton Shepelev <anton.txt@gmail.moc> writes:
>Hello, all
>
>I have decided to publish my implementaton of dymanic arrays

Dymanic?

"showing wild, apparently deranged, excitement and energy."?

Re: Dymamic arrays: memory management and naming

<OIsT67k9qtjog2FX0@bongo-ra.co>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: spi...@gmail.com (Spiros Bousbouras)
Newsgroups: comp.lang.c
Subject: Re: Dymamic arrays: memory management and naming
Date: Sun, 10 Sep 2023 17:57:28 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 50
Message-ID: <OIsT67k9qtjog2FX0@bongo-ra.co>
References: <20230909132336.99cdb303ad685bc1e40f92df@gmail.moc>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 10 Sep 2023 17:57:28 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b1edd11d25778e5965521fd7a2d5750c";
logging-data="711308"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/WJq8k99aiMEL+KUjqWIBV"
Cancel-Lock: sha1:tbar2XYWT9a06GvI2WCTNZpiQjw=
X-Server-Commands: nowebcancel
In-Reply-To: <20230909132336.99cdb303ad685bc1e40f92df@gmail.moc>
X-Organisation: Weyland-Yutani
 by: Spiros Bousbouras - Sun, 10 Sep 2023 17:57 UTC

On Sat, 9 Sep 2023 13:23:36 +0300
Anton Shepelev <anton.txt@gmail.moc> wrote:
> Hello, all
>
> I have decided to publish my implementaton of dymanic arrays
> that you helped me with back in 2018[1] (time rolls like a
> steamroller). The initial version will have a single built-
> in memory-management strategy, and I ask your opinion about
> one based on a fixed Fibonacci progerssion, so that the
> array size in bytes grows as: 1,2,3,5,8,13,... And of course
> it may start with any Fibonacci number if required. The
> purpose is to let the memory manager re-use the two previous
> adjacent allocations for the next one without any gaps.
>
> The fixed sizes help unify memory usage between different
> dymamic arrays. Do you think it worth the effort, or is a
> simple 1.5 growth factor relative to whatever the current
> capacity the array has better on the whole, in that it has a
> much higher ratio of efficiency to code complexity, for the
> Fibonacci approach will require the storage of the previous
> capacity and a lookup algorithm for cases when the
> programmer sets the array length explicitly (so that a
> request of 12 bytes results in a 13-byte allocation).

It is worth it for the originality factor , if nothing else ! I assume the
code will be open source and fairly small so if the user doesn't like it ,
he/she can always change it.

> Another question is function names. The current ones use
> the `da_' prefix:
>
> void* da_new ( size_t elem_sz ); /* create an array */
> void* da_newl ( size_t elem_sz, unsigned int len ); /* of specified length */
> void* da_setlen( void * a , unsigned int len ); /* set the length */
> int da_len ( void * a ); /* get the length */
> void* da_add ( void * a , void * data_p ); /* add an element */
> void* da_addemp( void * a , void ** elem_pp ); /* add an empty element */
> /* ..and provide its address for writing */
> void da_free ( void * a ); /* deallocate */
>
> Do you think the `a_' prefix would incur a significant risk
> of name collisions?

I wouldn't worry about it. Again , if it doesn't work for the user , they
can change it. Personally I would choose something more mnemonic like
dyna_ .

> 1. In two threads:
> <20181117143819.43938ee34006bbcc1826bf0c@gmail.com>
> <20181119022614.5cf93af72a29cb41cdc86910@gmail.com>

Re: Dymamic arrays: memory management and naming

<20230910234917.8a6dd40b27f4a9792ccae6bb@gmail.moc>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton....@gmail.moc (Anton Shepelev)
Newsgroups: comp.lang.c
Subject: Re: Dymamic arrays: memory management and naming
Date: Sun, 10 Sep 2023 23:49:17 +0300
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <20230910234917.8a6dd40b27f4a9792ccae6bb@gmail.moc>
References: <20230909132336.99cdb303ad685bc1e40f92df@gmail.moc>
<OIsT67k9qtjog2FX0@bongo-ra.co>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="b679b7dd1b639d3c9f159790492bb539";
logging-data="760301"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/nVQbMaZa5yow+UjiqdpdI/lbz4RbcoKQ="
Cancel-Lock: sha1:uVOpkfOtenkyPTpvCz6ubcHAuJk=
X-Newsreader: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
 by: Anton Shepelev - Sun, 10 Sep 2023 20:49 UTC

Spiros Bousbouras to Anton Shepelev:

> > The initial version will have a single built- in memory-
> > management strategy, and I ask your opinion about one
> > based on a fixed Fibonacci progerssion
>
> It is worth it for the originality factor , if nothing
> else ! I assume the code will be open source and fairly
> small so if the user doesn't like it , he/she can always
> change it.

Well, I have decided to follow Kaz's advice and publish the
simplest think that works. Then I will add support for
custom allocation strategies and provide the Fibonacci one
as an option.

> > Do you think the `a_' prefix would incur a significant
> > risk of name collisions?
>
> I wouldn't worry about it. Again , if it doesn't work for
> the user , they can change it.

The ability to use third-party code as-is is an advantage.

> Personally I would choose something more mnemonic like
> dyna_ .

I suppose that whoever decides to use my library will use it
intensively, because dynamic arrays are a very fundamental
and highly-demanded data-structure, and my principle is to
make indentifier length inversely proportinal to use
frequency, so I will start with `a_' and will consider a) a
custom prefix specifiable via a macro and b) global
structure with function pointers, so that the user may
"import" it into his code under whatever name he please,
somewhat similar to the import facilities in Modula, Python,
and Javascript.

--
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments

Re: Dymamic arrays: memory management and naming

<20230910140820.371@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Dymamic arrays: memory management and naming
Date: Sun, 10 Sep 2023 21:25:46 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 43
Message-ID: <20230910140820.371@kylheku.com>
References: <20230909132336.99cdb303ad685bc1e40f92df@gmail.moc>
<OIsT67k9qtjog2FX0@bongo-ra.co>
<20230910234917.8a6dd40b27f4a9792ccae6bb@gmail.moc>
Injection-Date: Sun, 10 Sep 2023 21:25:46 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b79f240c77e071cf5b4c1879315f9535";
logging-data="770629"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19TdBhmtgi+NAbBt/vCGuhkX34T9xwZuU8="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:uJZBBI/B4fDpWeiR9hRxZK0gHxs=
 by: Kaz Kylheku - Sun, 10 Sep 2023 21:25 UTC

On 2023-09-10, Anton Shepelev <anton.txt@gmail.moc> wrote:
>> I wouldn't worry about it. Again , if it doesn't work for
>> the user , they can change it.
>
> The ability to use third-party code as-is is an advantage.

A clash does not always mean that a user has to edit your
code.

If the user's program is not actually using the clashing identifier
(they are only using yours, not the unrelated other one coming from
somewhere), they can use #define to rename it out of the way.

#define is so effective that you can take C code which uses identifiers
like "class" and "new" and make it compile as C++ without renaming
those symbols in the code.

If you're converting the code to C++ which uses "class"
and "new", then you can't do that.

In the TXR project, I use the #define trick to work around
a few cases of identifier pollution from system headers.

This is needed only on BSD systems and derivatives,
which have broken feature selection.

The ./configure script detects whether the clashes are present and for
the symbols in question it emits #define renames, deposited into
config.h.

One example is the identifier "mergesort". That comes from some BSD
header in such a way that I can't disable it without losing some
needed declarations. I happen to have a function called "mergesort",
which I'm reluctant to rename; why should i?

The configure script detects that, adds #define mergesort txr_mergesort
and all is well.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: Dymamic arrays: memory management and naming

<86il8fm1mu.fsf@linuxsc.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: Dymamic arrays: memory management and naming
Date: Tue, 12 Sep 2023 16:07:37 -0700
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <86il8fm1mu.fsf@linuxsc.com>
References: <20230909132336.99cdb303ad685bc1e40f92df@gmail.moc>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="fe728774cf09d257108abae3eebaf7e0";
logging-data="1875884"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/FVQu5xBIpnyZatuYTzTNUHSkQBus6e/M="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:DyJI9C7f+52b/C6vcgD42Eq8QsI=
sha1:WAwBAF/PiOxbeYYYVTATr412YAc=
 by: Tim Rentsch - Tue, 12 Sep 2023 23:07 UTC

Anton Shepelev <anton.txt@gmail.moc> writes:

> I have decided to publish my implementaton of dymanic arrays
> [...] The initial version will have a single built-
> in memory-management strategy, and I ask your opinion about
> one based on a fixed Fibonacci progerssion, so that the
> array size in bytes grows as: 1,2,3,5,8,13,... [...]
>
> Do you think it worth the effort, or is a
> simple 1.5 growth factor [...] better on the whole, [...]
>
> Another question is function names. The current ones use
> the `da_' prefix [is a simpler 'a_' prefix okay instead?]

My reactions/comments/suggestions, for what they are worth:

One: simpler is better. I am skeptical that the complications
of using Fibonacci sizes will be worth the effort.

Two: my intuition says that a fixed growth factor has issues
when considered over a large range of sizes. I tend to favor a
larger growth factor (eg, 2x) for small sizes and a smaller
growth factor (eg, + size/4 or even + size/16) for very large
sizes, with a 1.5 growth factor in between. How many steps
there are and where the transitions should be is up to you.

Three: personally I think the 'da_' prefix is a better choice
than the shorter 'a_' prefix. No basis for that suggestion, just
a gut reaction.

Re: Dymamic arrays: memory management and naming

<20230917004418.1373d90f4b078452d0c24502@gmail.moc>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton....@gmail.moc (Anton Shepelev)
Newsgroups: comp.lang.c
Subject: Re: Dymamic arrays: memory management and naming
Date: Sun, 17 Sep 2023 00:44:18 +0300
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <20230917004418.1373d90f4b078452d0c24502@gmail.moc>
References: <20230909132336.99cdb303ad685bc1e40f92df@gmail.moc>
<86il8fm1mu.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="d2ebfe979734f6b8359231ac9a3bded0";
logging-data="12906"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+3Y03Pla3wgWO3vYPcAlAbrGO8lDZwYPo="
Cancel-Lock: sha1:XiWRpGYUK6Kgxb5elDppR+49GcA=
X-Newsreader: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
 by: Anton Shepelev - Sat, 16 Sep 2023 21:44 UTC

Tim Rentsch:

> my intuition says that a fixed growth factor has issues
> when considered over a large range of sizes. I tend to
> favor a larger growth factor (eg, 2x) for small sizes and
> a smaller growth factor (eg, + size/4 or even + size/16)
> for very large sizes, with a 1.5 growth factor in between.

I will remember your suggestion, in order later to implement
it as a custom growth strategy with the growth factor
determined by sigmoid function of array size, startng with a
large value and asymptotically converging to a smaller one.

--
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments

Re: Dymamic arrays: memory management and naming

<86ediwmk8b.fsf@linuxsc.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: Dymamic arrays: memory management and naming
Date: Sun, 17 Sep 2023 16:51:48 -0700
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <86ediwmk8b.fsf@linuxsc.com>
References: <20230909132336.99cdb303ad685bc1e40f92df@gmail.moc>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="eea9b3fa2266531b102f184a126e7979";
logging-data="641306"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+dkPtbD6Iy3OnXzCxohAg2FRF5a64e+T0="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:Ky2mSawUJc/EmTdoktphjUMhByY=
sha1:hgkArPwYjr1CJRqRRtEhatkC0Uc=
 by: Tim Rentsch - Sun, 17 Sep 2023 23:51 UTC

Anton Shepelev <anton.txt@gmail.moc> writes:

> Hello, all
>
> I have decided to publish my implementaton of dymanic arrays
> that you helped me with back in 2018[1] (time rolls like a
> steamroller). The initial version will have a single built-
> in memory-management strategy, and I ask your opinion about
> one based on a fixed Fibonacci progerssion, so that the
> array size in bytes grows as: 1,2,3,5,8,13,... [...]

Another point to consider: if you are using malloc(), and
the array elements might be small (eg chars or shorts), you
might try to take into account minimum allocation size,
grain, and overhead. Here is a program to help explain:

#include <stdio.h>
#include <stdlib.h>

int
main(){
enum { N = 90 };
char *blocks[N+1];
unsigned i;
for( i = 0; i < N+1; i++ ){
blocks[i] = malloc( i );
}
for( i = 0; i < N; i++ ){
printf( "i: %2u delta: %3td\n", i, blocks[i+1] - blocks[i] );
}
}

Running this program on my system here, it indicates a grain
of 16 bytes, an overhead of 8 bytes, and a minimum allocation
size of 24 bytes. That is, any allocation of 24 bytes or less
is the same as asking for 24 bytes, and any larger requests
add 8 and then round up to a multiple of 16 (so asking for 40
bytes uses 48 of memory, asking for 41 bytes uses 64 bytes of
memory, etc). Adjusting the choice of growth amount to take
these factors into account should give more efficient use of
memory (as mentioned, for small element sizes). Note that the
various parameters can be determined dynamically at startup,
so they don't need to be hard coded or anything like that.

(Yes I know this program has undefined behavior. Despite that
it is still useful.)

Re: Dymamic arrays: memory management and naming

<20230919011018.d9ed14da6e842291d47b69d7@gmail.moc>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton....@gmail.moc (Anton Shepelev)
Newsgroups: comp.lang.c
Subject: Re: Dymamic arrays: memory management and naming
Date: Tue, 19 Sep 2023 01:10:18 +0300
Organization: A noiseless patient Spider
Lines: 55
Message-ID: <20230919011018.d9ed14da6e842291d47b69d7@gmail.moc>
References: <20230909132336.99cdb303ad685bc1e40f92df@gmail.moc>
<86ediwmk8b.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="41d0fdabbeca28057c748ba2dcaee8cc";
logging-data="2081176"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18CU2s8T5xOEYsAWOgLRYnaGE3E63Voyys="
Cancel-Lock: sha1:isMtEuntvGWlMVx2qRY7mg+6gM0=
X-Newsreader: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
 by: Anton Shepelev - Mon, 18 Sep 2023 22:10 UTC

Tim Rentsch:

> Another point to consider: if you are using malloc(), and
> the array elements might be small (eg chars or shorts),

I thought such effects should be prominent only with small
array elements /and/ small array lengthes... I expected them
to drown below the noise floor (so to say) when the length
becomes large.

> you
> might try to take into account minimum allocation size,
> grain, and overhead. Here is a program to help explain:
>
> #include <stdio.h>
> #include <stdlib.h>
>
> int
> main(){
> enum { N = 90 };
> char *blocks[N+1];
> unsigned i;
> for( i = 0; i < N+1; i++ ){
> blocks[i] = malloc( i );
> }
> for( i = 0; i < N; i++ ){
> printf( "i: %2u delta: %3td0, i, blocks[i+1] - blocks[i] );
> }
> }
>
> Running this program on my system here, it indicates a grain
> of 16 bytes, an overhead of 8 bytes

Same here (on the Freeshell.de server). I had not thought
of that at all, assuming subconsicously that the allocation
map (some sort of RAM filesystem) is kept separately from
the actual allocated blocks. May I rely on the
contiguousness of each overhead data element with the
corresponding allocated block of data? May I rely in
general on the sequential order of allocations that your
program clearly demonstrated in both our cases? For aught I
know, the memory manager is free to do howsoever it wishes...

Thanks for the observation, Tim. As you see, it is somewhat
below the horison (gelogically speaking) of my knowledge.
If you should care to provide a strategy that estimates
these parameters of the memory manager and then uses them to
optimise the allocation of dynamic arrays, I shall gladly
include it as as an option with my implementation. Right now
I am casting for some lean, clean, and not git-driven platform
to host the code.

--
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments

Re: Dymamic arrays: memory management and naming

<86o7hyky4u.fsf@linuxsc.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: Dymamic arrays: memory management and naming
Date: Tue, 19 Sep 2023 07:58:57 -0700
Organization: A noiseless patient Spider
Lines: 117
Message-ID: <86o7hyky4u.fsf@linuxsc.com>
References: <20230909132336.99cdb303ad685bc1e40f92df@gmail.moc> <86ediwmk8b.fsf@linuxsc.com> <20230919011018.d9ed14da6e842291d47b69d7@gmail.moc>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="2708376e434a174750b1cbd4a8683397";
logging-data="2530628"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/hYcKi1HnEiki2vY4slRrk1AxEK/sL0lM="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:JKuZTWMTjl7pN2ri+OWWVunK3NU=
sha1:J8dUbw8cfHqQDkYvonTgN1zB48c=
 by: Tim Rentsch - Tue, 19 Sep 2023 14:58 UTC

Anton Shepelev <anton.txt@gmail.moc> writes:

> Tim Rentsch:
>
>> Another point to consider: if you are using malloc(), and
>> the array elements might be small (eg chars or shorts),
>
> I thought such effects should be prominent only with small
> array elements /and/ small array lengthes... I expected them
> to drown below the noise floor (so to say) when the length
> becomes large.

I think it's not as simple as that. Consider a scenario: a
program is making use of a growable character buffer, with
eventually 150 bytes needed. Let's take an initial guess of 8
elements, and growing by a factor of two. The chain of events in
the two cases would look like

(ignore grain, etc) 8 16 32 64 128 256 (272 used)
(factor in grain, etc) 24 56 120 248 (256 used)

Taking granularity, etc, into account the program needs just four
allocations (and uses only slightly less memory). Ignoring these
factors the program needs six allocations. Granted, the memory
savings is only about 6 percent, but there is also a time savings
by virtue of needing fewer re-allocations.

(If the numbers in the second line are confusing, remember that
at each stage the numbers are rounded up to be 8 mod 16. The
initial 24 is because that's the smallest amount of memory that
the allocator will fit in a single block; any smaller amount
will end up returning 24 usable bytes, so we might as well ask
for that.)

I admit this is only one scenario, and other scenarios will give
different results, including some where a naive approach does
better. Still, the potential upside seems worth getting, since
the cost of getting it (basically some simple arithmetic in the
allocation function) is pretty small.

>> you
>> might try to take into account minimum allocation size,
>> grain, and overhead. Here is a program to help explain:
>>
>> #include <stdio.h>
>> #include <stdlib.h>
>>
>> int
>> main(){
>> enum { N = 90 };
>> char *blocks[N+1];
>> unsigned i;
>> for( i = 0; i < N+1; i++ ){
>> blocks[i] = malloc( i );
>> }
>> for( i = 0; i < N; i++ ){
>> printf( "i: %2u delta: %3td0, i, blocks[i+1] - blocks[i] );
>> }
>> }
>>
>> Running this program on my system here, it indicates a grain
>> of 16 bytes, an overhead of 8 bytes
>
> Same here (on the Freeshell.de server). I had not thought
> of that at all, assuming subconsciously that the allocation
> map (some sort of RAM filesystem) is kept separately from
> the actual allocated blocks. May I rely on the
> contiguousness of each overhead data element with the
> corresponding allocated block of data?

I think most allocators use a little bit of memory just before
each allocated block, to facilitate free()-ing and coalescing of
adjacent free blocks. That isn't guaranteed of course, but it's
common.

> May I rely in
> general on the sequential order of allocations that your
> program clearly demonstrated in both our cases?

When a program starts it's likely that the allocator has a single
large block of memory available, and will fill successive calls
at one end of that block. Again, not guaranteed, but I expect
it occurs often enough that it's worth making a stab.

If an attempt to discover the allocator characteristics fails, I
think a reasonable fallback is to guess a granularity of 16 and
an overhead of 8 (minimum size 24) for 64-bit systems, and half
of those for 32-bit systems.

> For aught I
> know, the memory manager is free to do howsoever it wishes...

Certainly it is, but it's not just a coincidence that the
numbers you got match the numbers that I got.

Having said that, I should add that my experience with MS Windows
is that it has enormous amount of overhead for each allocated
block.

> Thanks for the observation, Tim. As you see, it is somewhat
> below the horizon (geologically speaking) of my knowledge.
> If you should care to provide a strategy that estimates
> these parameters of the memory manager and then uses them to
> optimise the allocation of dynamic arrays, I shall gladly
> include it as as an option with my implementation. Right now
> I am casting for some lean, clean, and not git-driven platform
> to host the code.

My first suggestion is to provide an option (runtime selectable)
that guesses 'sizeof (size_t)' for overhead, twice that for the
granularity, and three times that for the minimum request size.
It's probably worth adding an initialization call to your
allocator interface, so that you can later add code that tries to
discover the true values of these parameters.

(Note: some spelling corrections to your message have been
made.)

Re: Dymamic arrays: memory management and naming

<86jzsmkqyu.fsf@linuxsc.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: Dymamic arrays: memory management and naming
Date: Tue, 19 Sep 2023 10:33:45 -0700
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <86jzsmkqyu.fsf@linuxsc.com>
References: <20230909132336.99cdb303ad685bc1e40f92df@gmail.moc> <86ediwmk8b.fsf@linuxsc.com> <20230919011018.d9ed14da6e842291d47b69d7@gmail.moc>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="2708376e434a174750b1cbd4a8683397";
logging-data="2584366"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/q+B07b/+eB1Hdsq8tOPUGSkLlHqBiJZA="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:ZnZ9uWe4C97WU1jbJh7T8VVz39w=
sha1:gjhFgYi4J7zxnD2J91wU89EWTcA=
 by: Tim Rentsch - Tue, 19 Sep 2023 17:33 UTC

Anton Shepelev <anton.txt@gmail.moc> writes:

One further thought...

As of C11, there is a type max_align_t, defined in <stddef.h>,
whose alignment is the maximum alignment supported by the
implementation. The grain size for allocation should be a
multiple of

_Alignof (max_align_t)

so this alignment can be supported. Also, the amount of space
you use for your "pre-array" metadata should be chosen to be
a multiple of _Alignof (max_align_t), otherwise the array
alignments might be off in some cases.

Note by the way that sizeof (max_align_t) might not be the same
as _Alignof (max_align_t).

Re: Dymamic arrays: memory management and naming

<87led1izo1.fsf@nosuchdomain.example.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: Dymamic arrays: memory management and naming
Date: Tue, 19 Sep 2023 15:08:46 -0700
Organization: None to speak of
Lines: 18
Message-ID: <87led1izo1.fsf@nosuchdomain.example.com>
References: <20230909132336.99cdb303ad685bc1e40f92df@gmail.moc>
<86ediwmk8b.fsf@linuxsc.com>
<20230919011018.d9ed14da6e842291d47b69d7@gmail.moc>
<86jzsmkqyu.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="c95a7bd4ec59e911bcb03685ef3cdd0a";
logging-data="2685926"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18xCwsXcoawxLSer/BoQ/7r"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:vADUxkLCiWxnX2G3ma6gudxldS4=
sha1:Ii5mi/DnaZI9nltI0ilxtEPVC4A=
 by: Keith Thompson - Tue, 19 Sep 2023 22:08 UTC

Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
[...]
> Note by the way that sizeof (max_align_t) might not be the same
> as _Alignof (max_align_t).

Indeed. I was curious about this, so I wrote a small test program that
shows that _Alignof (max_align_t) is 16, but sizeof (max_align_t) is 32
on the implementation I'm using.

I'm using gcc, which defines max_align_t as a struct containing a long
long, a long double, and optionally a __float128. It could have reduced
the size by making it a union rather than a struct, but there's rarely
(?) any reason to create objects of type max_align_t.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

Re: Dymamic arrays: memory management and naming

<ued7of$2idh4$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: Dymamic arrays: memory management and naming
Date: Tue, 19 Sep 2023 15:35:58 -0700
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <ued7of$2idh4$1@dont-email.me>
References: <20230909132336.99cdb303ad685bc1e40f92df@gmail.moc>
<86ediwmk8b.fsf@linuxsc.com>
<20230919011018.d9ed14da6e842291d47b69d7@gmail.moc>
<86jzsmkqyu.fsf@linuxsc.com> <87led1izo1.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 19 Sep 2023 22:35:59 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="f6fa32ff36e5d8cee5f47474b078ec61";
logging-data="2700836"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19YP5rmrhDf2BhIXHYHbXQBINkAc2CZDGM="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:mapBMi6Y1yzbVKE0vKAYotJpV4g=
Content-Language: en-US
In-Reply-To: <87led1izo1.fsf@nosuchdomain.example.com>
 by: Chris M. Thomasson - Tue, 19 Sep 2023 22:35 UTC

On 9/19/2023 3:08 PM, Keith Thompson wrote:
> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
> [...]
>> Note by the way that sizeof (max_align_t) might not be the same
>> as _Alignof (max_align_t).
>
> Indeed. I was curious about this, so I wrote a small test program that
> shows that _Alignof (max_align_t) is 16, but sizeof (max_align_t) is 32
> on the implementation I'm using.
>
> I'm using gcc, which defines max_align_t as a struct containing a long
> long, a long double, and optionally a __float128. It could have reduced
> the size by making it a union rather than a struct, but there's rarely
> (?) any reason to create objects of type max_align_t.
>

Check out this old code of mine:

https://pastebin.com/raw/f37a23918

Re: Dymamic arrays: memory management and naming

<20230919154533.263@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Dymamic arrays: memory management and naming
Date: Tue, 19 Sep 2023 22:49:51 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <20230919154533.263@kylheku.com>
References: <20230909132336.99cdb303ad685bc1e40f92df@gmail.moc>
<86ediwmk8b.fsf@linuxsc.com>
<20230919011018.d9ed14da6e842291d47b69d7@gmail.moc>
<86jzsmkqyu.fsf@linuxsc.com> <87led1izo1.fsf@nosuchdomain.example.com>
Injection-Date: Tue, 19 Sep 2023 22:49:51 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b0a008d922e8913c94514619367ad5e6";
logging-data="2704288"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ro7Lx3UQLMwhKkAg1F8yQkAofkrcqV50="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:nQrR3JwibXcsjUp7fn7UFXpBm3I=
 by: Kaz Kylheku - Tue, 19 Sep 2023 22:49 UTC

On 2023-09-19, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
> [...]
>> Note by the way that sizeof (max_align_t) might not be the same
>> as _Alignof (max_align_t).
>
> Indeed. I was curious about this, so I wrote a small test program that
> shows that _Alignof (max_align_t) is 16, but sizeof (max_align_t) is 32
> on the implementation I'm using.
>
> I'm using gcc, which defines max_align_t as a struct containing a long
> long, a long double, and optionally a __float128. It could have reduced
> the size by making it a union rather than a struct, but there's rarely
> (?) any reason to create objects of type max_align_t.

Yes there is!

union {
foo_t x;
bar_t y;

// please give my own union maximum alignment --- without undue bloat

max_align_t align;
}

A max_align_t that can only be used as _Alignof(max_align_t) is useless;
it might as well be a #define ALIGN_MAX 16 constant in some header
like <limits.h>.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: Dymamic arrays: memory management and naming

<86fs39l8xp.fsf@linuxsc.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: Dymamic arrays: memory management and naming
Date: Tue, 19 Sep 2023 22:17:54 -0700
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <86fs39l8xp.fsf@linuxsc.com>
References: <20230909132336.99cdb303ad685bc1e40f92df@gmail.moc> <86ediwmk8b.fsf@linuxsc.com> <20230919011018.d9ed14da6e842291d47b69d7@gmail.moc> <86jzsmkqyu.fsf@linuxsc.com> <87led1izo1.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="f37cc0880943bcff334da4514aca8b8d";
logging-data="2940954"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+LQtQbXL0g2S+0o9FuvWYBtrr95E1OQ3U="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:zT5WkG+DOrXFhT+eNhFDNOX+MvE=
sha1:gRO6TKapntj4k3G4dzSFGcGZa7g=
 by: Tim Rentsch - Wed, 20 Sep 2023 05:17 UTC

Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
> [...]
>
>> Note by the way that sizeof (max_align_t) might not be the same
>> as _Alignof (max_align_t).
>
> Indeed. I was curious about this, so I wrote a small test program that
> shows that _Alignof (max_align_t) is 16, but sizeof (max_align_t) is 32
> on the implementation I'm using.

That's just what I did. :)

> I'm using gcc, which defines max_align_t as a struct containing a long
> long, a long double, and optionally a __float128. It could have reduced
> the size by making it a union rather than a struct, but there's rarely
> (?) any reason to create objects of type max_align_t.

AFAICT there is never any reason to use max_align_t as the
type in any declaration, excepting perhaps for probing the
environment like the little test programs mentioned.

Re: Dymamic arrays: memory management and naming

<86bkdxl8da.fsf@linuxsc.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: Dymamic arrays: memory management and naming
Date: Tue, 19 Sep 2023 22:30:09 -0700
Organization: A noiseless patient Spider
Lines: 51
Message-ID: <86bkdxl8da.fsf@linuxsc.com>
References: <20230909132336.99cdb303ad685bc1e40f92df@gmail.moc> <86ediwmk8b.fsf@linuxsc.com> <20230919011018.d9ed14da6e842291d47b69d7@gmail.moc> <86jzsmkqyu.fsf@linuxsc.com> <87led1izo1.fsf@nosuchdomain.example.com> <20230919154533.263@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="f37cc0880943bcff334da4514aca8b8d";
logging-data="2945668"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18HNZda+hAqJxvi9UzMjgV//ZKOpCGe83I="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:rKan3y5UtPcQutWQtFp/1nl0rTI=
sha1:g5487PWX9wP4kDKRXHqCOqdEwzo=
 by: Tim Rentsch - Wed, 20 Sep 2023 05:30 UTC

Kaz Kylheku <864-117-4973@kylheku.com> writes:

> On 2023-09-19, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
>
>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>> [...]
>>
>>> Note by the way that sizeof (max_align_t) might not be the same
>>> as _Alignof (max_align_t).
>>
>> Indeed. I was curious about this, so I wrote a small test program that
>> shows that _Alignof (max_align_t) is 16, but sizeof (max_align_t) is 32
>> on the implementation I'm using.
>>
>> I'm using gcc, which defines max_align_t as a struct containing a long
>> long, a long double, and optionally a __float128. It could have reduced
>> the size by making it a union rather than a struct, but there's rarely
>> (?) any reason to create objects of type max_align_t.
>
> Yes there is!
>
> union {
> foo_t x;
> bar_t y;
>
> // please give my own union maximum alignment --- without undue bloat
>
> max_align_t align;
> }
>
> A max_align_t that can only be used as _Alignof(max_align_t) is useless;
> it might as well be a #define ALIGN_MAX 16 constant in some header
> like <limits.h>.

You need to think harder.

One: it's easy to get the alignment result you want
without using max_align_t as the type of a member (or
any other object).

Two: there are advantages to having max_align_t be a
type, so it can be used with _Alignas, that are
harder to accomplish if the value is just a #define.

Three: it can be more convenient for an implementation
to provide the max_align_t type as a type than it is
to have to construct the value in the preprocessor
(where sizeof and _Alignof don't work). Witness how
this information is provided in the gcc library
header - much easier than having to figure out the
value 16 and put it in a #define.

Re: Dymamic arrays: memory management and naming

<87pm2d18j3.fsf@nosuchdomain.example.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: Dymamic arrays: memory management and naming
Date: Wed, 20 Sep 2023 02:46:56 -0700
Organization: None to speak of
Lines: 49
Message-ID: <87pm2d18j3.fsf@nosuchdomain.example.com>
References: <20230909132336.99cdb303ad685bc1e40f92df@gmail.moc>
<86ediwmk8b.fsf@linuxsc.com>
<20230919011018.d9ed14da6e842291d47b69d7@gmail.moc>
<86jzsmkqyu.fsf@linuxsc.com> <87led1izo1.fsf@nosuchdomain.example.com>
<20230919154533.263@kylheku.com> <86bkdxl8da.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="c95a7bd4ec59e911bcb03685ef3cdd0a";
logging-data="3034509"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19X5Dyxo93tQ4VjBsaVaAnP"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:UHSrx702dXE0/4ZAAxOCsUgsLTY=
sha1:e+igKqd3Clj1CJ21iKbtCNEDYzw=
 by: Keith Thompson - Wed, 20 Sep 2023 09:46 UTC

Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
> Kaz Kylheku <864-117-4973@kylheku.com> writes:
>
>> On 2023-09-19, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
>>
>>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>> [...]
>>>
>>>> Note by the way that sizeof (max_align_t) might not be the same
>>>> as _Alignof (max_align_t).
>>>
>>> Indeed. I was curious about this, so I wrote a small test program that
>>> shows that _Alignof (max_align_t) is 16, but sizeof (max_align_t) is 32
>>> on the implementation I'm using.
>>>
>>> I'm using gcc, which defines max_align_t as a struct containing a long
>>> long, a long double, and optionally a __float128. It could have reduced
>>> the size by making it a union rather than a struct, but there's rarely
>>> (?) any reason to create objects of type max_align_t.
>>
>> Yes there is!
>>
>> union {
>> foo_t x;
>> bar_t y;
>>
>> // please give my own union maximum alignment --- without undue bloat
>>
>> max_align_t align;
>> }
>>
>> A max_align_t that can only be used as _Alignof(max_align_t) is useless;
>> it might as well be a #define ALIGN_MAX 16 constant in some header
>> like <limits.h>.
>
> You need to think harder.
>
> One: it's easy to get the alignment result you want
> without using max_align_t as the type of a member (or
> any other object).

How? I don't think _Alignas can be used for this.

[...]

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

Re: Dymamic arrays: memory management and naming

<864jjpkkgu.fsf@linuxsc.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: Dymamic arrays: memory management and naming
Date: Wed, 20 Sep 2023 07:06:25 -0700
Organization: A noiseless patient Spider
Lines: 70
Message-ID: <864jjpkkgu.fsf@linuxsc.com>
References: <20230909132336.99cdb303ad685bc1e40f92df@gmail.moc> <86ediwmk8b.fsf@linuxsc.com> <20230919011018.d9ed14da6e842291d47b69d7@gmail.moc> <86jzsmkqyu.fsf@linuxsc.com> <87led1izo1.fsf@nosuchdomain.example.com> <20230919154533.263@kylheku.com> <86bkdxl8da.fsf@linuxsc.com> <87pm2d18j3.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="f37cc0880943bcff334da4514aca8b8d";
logging-data="3124988"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX184lDbPqkIuIuYF/dXamxtABt6OfGKoWp8="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:urFRffCdPumivpqm9mzqqat9TcQ=
sha1:gPQjpoS3AEdGwRoUIFL6gBfGTPs=
 by: Tim Rentsch - Wed, 20 Sep 2023 14:06 UTC

Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>
>> Kaz Kylheku <864-117-4973@kylheku.com> writes:
>>
>>> On 2023-09-19, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
>>>
>>>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>>> [...]
>>>>
>>>>> Note by the way that sizeof (max_align_t) might not be the same
>>>>> as _Alignof (max_align_t).
>>>>
>>>> Indeed. I was curious about this, so I wrote a small test
>>>> program that shows that _Alignof (max_align_t) is 16, but sizeof
>>>> (max_align_t) is 32 on the implementation I'm using.
>>>>
>>>> I'm using gcc, which defines max_align_t as a struct containing a
>>>> long long, a long double, and optionally a __float128. It could
>>>> have reduced the size by making it a union rather than a struct,
>>>> but there's rarely (?) any reason to create objects of type
>>>> max_align_t.
>>>
>>> Yes there is!
>>>
>>> union {
>>> foo_t x;
>>> bar_t y;
>>>
>>> // please give my own union maximum alignment
>>> // [but] without undue bloat
>>>
>>> max_align_t align;
>>> }
>>>
>>> A max_align_t that can only be used as _Alignof(max_align_t) is
>>> useless; it might as well be a #define ALIGN_MAX 16 constant in
>>> some header like <limits.h>.
>>
>> You need to think harder.
>>
>> One: it's easy to get the alignment result you want
>> without using max_align_t as the type of a member (or
>> any other object).
>
> How? I don't think _Alignas can be used for this.
>
> [...]

I haven't used the new alignment features really at all
until just recently, but it took only a few minutes to
find this:

#include <stddef.h>

union au {
int x;
short y;
_Alignas (max_align_t) char stuff[ 1 ];
};

It isn't necessary to make the 'stuff' member be an array,
that was just the first thought I had (well, that worked).
My test program shows this type has a size of 16 and an
alignment of 16.

Incidentally, the only resource I consulted to understand
how the new alignment features work is the C11 (draft)
standard.

Re: Dymamic arrays: memory management and naming

<20230920080251.690@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Dymamic arrays: memory management and naming
Date: Wed, 20 Sep 2023 21:03:37 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 63
Message-ID: <20230920080251.690@kylheku.com>
References: <20230909132336.99cdb303ad685bc1e40f92df@gmail.moc>
<86ediwmk8b.fsf@linuxsc.com>
<20230919011018.d9ed14da6e842291d47b69d7@gmail.moc>
<86jzsmkqyu.fsf@linuxsc.com> <87led1izo1.fsf@nosuchdomain.example.com>
<20230919154533.263@kylheku.com> <86bkdxl8da.fsf@linuxsc.com>
Injection-Date: Wed, 20 Sep 2023 21:03:37 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b0a008d922e8913c94514619367ad5e6";
logging-data="3283436"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/bjEQPk0vIn7Cwj3Di/FIj1r+h6/CkYew="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:kHa/skRQ34BnsaKPN6uO2AXyqIQ=
 by: Kaz Kylheku - Wed, 20 Sep 2023 21:03 UTC

On 2023-09-20, Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
> Kaz Kylheku <864-117-4973@kylheku.com> writes:
>
>> On 2023-09-19, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
>>
>>> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>>> [...]
>>>
>>>> Note by the way that sizeof (max_align_t) might not be the same
>>>> as _Alignof (max_align_t).
>>>
>>> Indeed. I was curious about this, so I wrote a small test program that
>>> shows that _Alignof (max_align_t) is 16, but sizeof (max_align_t) is 32
>>> on the implementation I'm using.
>>>
>>> I'm using gcc, which defines max_align_t as a struct containing a long
>>> long, a long double, and optionally a __float128. It could have reduced
>>> the size by making it a union rather than a struct, but there's rarely
>>> (?) any reason to create objects of type max_align_t.
>>
>> Yes there is!
>>
>> union {
>> foo_t x;
>> bar_t y;
>>
>> // please give my own union maximum alignment --- without undue bloat
>>
>> max_align_t align;
>> }
>>
>> A max_align_t that can only be used as _Alignof(max_align_t) is useless;
>> it might as well be a #define ALIGN_MAX 16 constant in some header
>> like <limits.h>.
>
> You need to think harder.

I'm "thinking broader" instead, maybe?

> One: it's easy to get the alignment result you want
> without using max_align_t as the type of a member (or
> any other object).

Like almost everyone here, I know how to get my union aligned in
multiple ways.

It would be better if the above solution would Just Work too.

It uses widely portable syntax, only a definition of max_align_t is
required, which can be provided somehow if unavailable.

> Two: there are advantages to having max_align_t be a
> type, so it can be used with _Alignas, that are
> harder to accomplish if the value is just a #define.

Though I didn't intend to argue for the advantages of having these kinds
of values (also) as preprocessor constants, there are advantages.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: Dymamic arrays: memory management and naming

<20230924003915.51bb21339ab1c551eba59162@gmail.moc>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton....@gmail.moc (Anton Shepelev)
Newsgroups: comp.lang.c
Subject: Re: Dymamic arrays: memory management and naming
Date: Sun, 24 Sep 2023 00:39:15 +0300
Organization: A noiseless patient Spider
Lines: 57
Message-ID: <20230924003915.51bb21339ab1c551eba59162@gmail.moc>
References: <20230909132336.99cdb303ad685bc1e40f92df@gmail.moc>
<86ediwmk8b.fsf@linuxsc.com>
<20230919011018.d9ed14da6e842291d47b69d7@gmail.moc>
<86jzsmkqyu.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="7d582355463a45655b152f28c397efcd";
logging-data="1044651"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX197vMNpXVMPvdIaY6AdE0XcwqSh90xzfWY="
Cancel-Lock: sha1:3cwKHXCn2MJeq5yrmL8yinxSWRU=
X-Newsreader: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
 by: Anton Shepelev - Sat, 23 Sep 2023 21:39 UTC

Tim Rentsch:

> One further thought...
>
> As of C11, there is a type max_align_t, defined in
> <stddef.h>, whose alignment is the maximum alignment
> supported by the implementation. The grain size for
> allocation should be a multiple of
>
> _Alignof (max_align_t)

When did C abandon its style of lower case, underscore-
separated identifiers? Why not `alignof' or at least
`_alignof'?

> so this alignment can be supported. Also, the amount of
> space you use for your "pre-array" metadata should be
> chosen to be a multiple of _Alignof (max_align_t),
> otherwise the array alignments might be off in some cases.

Yes, I have discussed this issue here before, and
implemented a (I think Ben's) suggestion to calculate the
negative offset as the size of the metadata structure
rounded up to a power of two, which should ensure correct
alignment in most cases.

Futhermore, some systems seem not to require alignment,
e.g.:

#include <stdio.h>
#include <stdlib.h>

void print_as( char const * data )
{ for( int i = 0; i < 2; i += 1 )
{ printf( "%i ", *((short*)(data+i*2)) ); }
printf("\n");
}

int main()
{ char* const data = malloc(5);
for( int i = 0; i < 5; i += 1 )
{ data[i] = (char)i%2; }

print_as( data );
print_as( data+1 );

return 0;
}

On my shell server, this progrma works, printing:

256 256
1 1

--
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments

Re: Dymamic arrays: memory management and naming

<pan$36016$569dd459$1577a2d7$cbc9fd07@invalid.invalid>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!bluemanedhawk.eternal-september.org!.POSTED!not-for-mail
From: bluemane...@invalid.invalid (Blue-Maned_Hawk)
Newsgroups: comp.lang.c
Subject: Re: Dymamic arrays: memory management and naming
Date: Sat, 23 Sep 2023 21:48:22 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <pan$36016$569dd459$1577a2d7$cbc9fd07@invalid.invalid>
References: <20230909132336.99cdb303ad685bc1e40f92df@gmail.moc>
<86ediwmk8b.fsf@linuxsc.com>
<20230919011018.d9ed14da6e842291d47b69d7@gmail.moc>
<86jzsmkqyu.fsf@linuxsc.com>
<20230924003915.51bb21339ab1c551eba59162@gmail.moc>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 23 Sep 2023 21:48:22 -0000 (UTC)
Injection-Info: bluemanedhawk.eternal-september.org; posting-host="9ff7bcafcfdb620a31a9697b8b835aa7";
logging-data="1039901"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/5DzsvBC4HnGxI4JG6xKAb/32it4gcSA8="
User-Agent: Pan/0.154 (Izium; 517acf4)
Cancel-Lock: sha1:+0kSxr8ttgP1G5e/nSwUBZN6Rrg=
X-Face: Llanfair­pwllgwyngyllÂÂÃ
‚­
gogery­chwyrn­drobw
llÂ
­llan­tysilioÂÂÂÂ
­go go­goch
Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAIAAADYYG7QAAACh0lEQVRYw71Z21bD
MAzzevbfkr4cHjrSXJyL044+MDa6WLEl2SkvkrZ1AbAvXO+bUGSCPYnsuIVGMpm
ZLnjX718GhAKNsp8lON2F9VrhELwIgJlBepkZjA78rVK+FkmNhEJK76UsJlz8+E
rJsjrpYouhLo/SC6qPHgakFOR8wV9+8rCfO/I/oVnmUZUp42/LW2XkLj9TCFNM9
jp5g2EmHZgpYZjCOkYU7sXVogRylJqpdggoFLG1g09Flah/7kErCxzR9HgXPYsq
0glb9cxjIz2Vsk9AmAoCSxECpD713joMKjQqLAtmMqJmXjdVvlMnMQCVITotJd1
z+fh1f1NNo+vuc1KnhWUmY7t03vydTud9BbXCtN3L2PL3bK7JCNG0GHzuZxafyB
fxevCxpm1vrwZltqw6SILCcdoCE6PGQC8wZWDA9Or7Qp5s3lAZezys0nDazs9S9
R0TjwEiksRxLkNPC1NMMWPs1bj0Ei0Yuo+JVtFLuzP1NRJ16qXWN8DhhtmS4PDg
O6mqRxs4bEJrYt087mSIow/1VzW2oFlMQuiuIy/KsUagvhdw6hSjJGlIavbLF8x
j3X47bccLcUSi0dkWh1nUZNhANT1tHKUXrNxNLbd9KPb9wDDVrKwmPQMOPQ1oy6
k5I1DwzDeRJd3jVIhDAUxq3ngzJG4CCkNXZxZVMcjefoK2J0gUY2S3rxz/RuTFx
2zHd9U+obimJXMG4edsk/2j5pTU5G1MmzbRLxkfq5EiT1GGsidvMGzi+1goGb2l
GCrN+nGnV8xj3q3JLRDVPL96vUc7Z4aJ3TN1mVqWAMJMfG+Jxh6TQqP+92iZkCU
xtglds1AB6r0aiSHKcnFck+p/c/0CbacFLQcajGcAAAAASUVORK5CYII=
 by: Blue-Maned_Hawk - Sat, 23 Sep 2023 21:48 UTC

Anton Shepelev wrote:

> When did C abandon its style of lower case, underscore- separated
> identifiers? Why not `alignof' or at least `_alignof'?

It's the only option that they had. The standard reserves names beginning
with two underscores and names beginning with an underscore followed by a
_capital_ letter, and they don't want to introduce names outside of those
spaces. That being said, they introduced headers for the names they
_really_ wanted to use, such as your mentioned alignof, and in C23 those
extra names have been added to the language proper and some new names have
skipped the namespaces, such as the "new" typeof keyword.

--
Blue-Maned_Hawk│shortens to Hawk│/
blu.mɛin.dÊ°ak/│he/him/his/himself/
Mr. bluemanedhawk.github.io
I've always pronounced them /ʔæ.lɪg.nɑf/ and /ʔæ.lɪg.næz/.

Re: Dymamic arrays: memory management and naming

<ueod5m$171uk$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jameskuy...@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c
Subject: Re: Dymamic arrays: memory management and naming
Date: Sun, 24 Sep 2023 00:15:50 -0400
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <ueod5m$171uk$1@dont-email.me>
References: <20230909132336.99cdb303ad685bc1e40f92df@gmail.moc>
<86ediwmk8b.fsf@linuxsc.com>
<20230919011018.d9ed14da6e842291d47b69d7@gmail.moc>
<86jzsmkqyu.fsf@linuxsc.com>
<20230924003915.51bb21339ab1c551eba59162@gmail.moc>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 24 Sep 2023 04:15:51 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="02f9defeecc8712da321e422f8c6bcdf";
logging-data="1279956"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+YLXmUyTve/W3zSjdmBudIeewERKVS48M="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:L1C+D5xbIw8hTpeQAn9ncJdZCvQ=
Content-Language: en-US
In-Reply-To: <20230924003915.51bb21339ab1c551eba59162@gmail.moc>
 by: James Kuyper - Sun, 24 Sep 2023 04:15 UTC

On 9/23/23 17:39, Anton Shepelev wrote:
....
> When did C abandon its style of lower case, underscore-
> separated identifiers? ...

In C99. It was realized that whenever a new keyword was added, it should
be taken from the space of names that were reserved to the
implementation; otherwise, it could break previously legal user code
that used that identifier for some different, perfectly legal purpose.
That's why new keywords in that version of the standard included _Bool,
_Complex, and _Imaginary. All keywords introduced since that time have
generally obeyed that convention.

> ... Why not `alignof' or at least
> `_alignof'?

Because both"alignof" and "_alignof" are from the name space reserved
for users, and therefore might be in use in existing code.

Re: Dymamic arrays: memory management and naming

<KZf6tlV2s29qC6sCU@bongo-ra.co>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: spi...@gmail.com (Spiros Bousbouras)
Newsgroups: comp.lang.c
Subject: Re: Dymamic arrays: memory management and naming
Date: Sun, 24 Sep 2023 11:48:18 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <KZf6tlV2s29qC6sCU@bongo-ra.co>
References: <20230909132336.99cdb303ad685bc1e40f92df@gmail.moc> <86ediwmk8b.fsf@linuxsc.com> <20230919011018.d9ed14da6e842291d47b69d7@gmail.moc>
<86jzsmkqyu.fsf@linuxsc.com> <20230924003915.51bb21339ab1c551eba59162@gmail.moc>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 24 Sep 2023 11:48:18 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="20a465b40b5b10e208bd03bf4f21615d";
logging-data="1417103"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+zbkZ68Qtd/+bAHBIWjLw6"
Cancel-Lock: sha1:HqQmS+yYr+R+t/WS58cwWxDjZp0=
X-Server-Commands: nowebcancel
X-Organisation: Weyland-Yutani
In-Reply-To: <20230924003915.51bb21339ab1c551eba59162@gmail.moc>
 by: Spiros Bousbouras - Sun, 24 Sep 2023 11:48 UTC

On Sun, 24 Sep 2023 00:39:15 +0300
Anton Shepelev <anton.txt@gmail.moc> wrote:
> Futhermore, some systems seem not to require alignment,
> e.g.:
>
> #include <stdio.h>
> #include <stdlib.h>
>
> void print_as( char const * data )
> { for( int i = 0; i < 2; i += 1 )
> { printf( "%i ", *((short*)(data+i*2)) ); }

%hi would be more precise than %i .At the very least it saves the reader
the trouble of trying to collect from the various points in the standard
the information to decide whether just %i is also guaranteed to work.

> printf("\n");
> }
>
> int main()
> { char* const data = malloc(5);
> for( int i = 0; i < 5; i += 1 )
> { data[i] = (char)i%2; }

(char)i will be promoted to something else (most likely int) before the
% operation takes place so the cast is pointless. Even if you had written
(char)(i%2) , given the values involved I don't see the point.

> print_as( data );
> print_as( data+1 );
>
> return 0;
> }
>
> On my shell server, this progrma works, printing:
>
> 256 256
> 1 1

"works" depends on assumptions about the system where you ran this. I can
guess what those assumptions are but it's best to state them explicitly.

--
Offsets are structures. Structures are offsets.
Charles Melice
http://al.howardknight.net/?ID=169555586400

Pages:123
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor