Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #160147 > unrolled thread
| Started by | Manfred <noname@add.invalid> |
|---|---|
| First post | 2021-04-17 19:12 +0200 |
| Last post | 2021-04-28 00:02 -0700 |
| Articles | 20 on this page of 89 — 20 participants |
Back to article view | Back to comp.lang.c
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: No, C is not a simple language Manfred <noname@add.invalid> - 2021-04-17 19:12 +0200
Re: No, C is not a simple language silas poulson <Silas8642@hotmail.co.uk> - 2021-04-17 18:33 -0700
Re: No, C is not a simple language Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2021-04-18 02:10 +0000
Re: No, C is not a simple language silas poulson <Silas8642@hotmail.co.uk> - 2021-04-17 22:35 -0700
Re: No, C is not a simple language Real Troll <real.troll@trolls.com> - 2021-04-18 17:00 +0100
Re: No, C is not a simple language jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-18 21:52 +0200
Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-18 16:46 +0000
Re: No, C is not a simple language Manfred <noname@add.invalid> - 2021-04-18 20:30 +0200
Re: No, C is not a simple language Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-04-18 12:46 -0700
Re: No, C is not a simple language Manfred <noname@add.invalid> - 2021-04-18 22:53 +0200
Re: No, C is not a simple language Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-04-19 04:20 -0700
Re: No, C is not a simple language Thiago Adams <thiago.adams@gmail.com> - 2021-04-19 08:29 -0700
Re: No, C is not a simple language Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-04-19 13:21 -0700
Re: No, C is not a simple language Richard Damon <Richard@Damon-Family.org> - 2021-04-19 18:03 -0400
Re: No, C is not a simple language Bart <bc@freeuk.com> - 2021-04-20 00:50 +0100
Re: No, C is not a simple language David Brown <david.brown@hesbynett.no> - 2021-04-20 08:32 +0200
Re: No, C is not a simple language Richard Damon <Richard@Damon-Family.org> - 2021-04-20 07:17 -0400
Re: No, C is not a simple language David Brown <david.brown@hesbynett.no> - 2021-04-20 14:25 +0200
Re: No, C is not a simple language Bart <bc@freeuk.com> - 2021-04-20 14:09 +0100
Re: No, C is not a simple language Richard Damon <Richard@Damon-Family.org> - 2021-04-20 10:19 -0400
Re: No, C is not a simple language James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-04-20 11:50 -0400
Re: No, C is not a simple language Richard Damon <Richard@Damon-Family.org> - 2021-04-20 12:06 -0400
Re: No, C is not a simple language James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-04-20 19:13 -0400
Re: No, C is not a simple language Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-05-11 05:29 -0700
Re: No, C is not a simple language David Brown <david.brown@hesbynett.no> - 2021-05-11 14:37 +0200
Re: No, C is not a simple language Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-05-11 05:18 -0700
Re: No, C is not a simple language Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-05-11 05:14 -0700
Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-19 07:18 +0000
Re: No, C is not a simple language Manfred <noname@add.invalid> - 2021-04-19 17:15 +0200
Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-20 04:05 +0000
Re: No, C is not a simple language Manfred <noname@add.invalid> - 2021-04-20 18:27 +0200
Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-20 16:41 +0000
Re: No, C is not a simple language jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-20 19:44 +0200
Re: No, C is not a simple language Thiago Adams <thiago.adams@gmail.com> - 2021-04-20 11:04 -0700
Re: No, C is not a simple language jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-20 20:23 +0200
Re: No, C is not a simple language Thiago Adams <thiago.adams@gmail.com> - 2021-04-20 12:22 -0700
Re: No, C is not a simple language Kaz Kylheku <563-365-8930@kylheku.com> - 2021-04-20 19:37 +0000
Re: No, C is not a simple language Kaz Kylheku <563-365-8930@kylheku.com> - 2021-04-20 18:30 +0000
Re: No, C is not a simple language jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-20 20:47 +0200
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-20 13:29 -0700
Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-21 04:37 +0000
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-21 15:26 -0700
Re: No, C is not a simple language Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2021-04-22 05:59 -0700
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-22 11:58 -0700
Re: No, C is not a simple language Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2021-04-23 07:23 -0700
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-24 14:26 -0700
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-24 14:28 -0700
Re: No, C is not a simple language Richard Damon <Richard@Damon-Family.org> - 2021-04-20 14:46 -0400
Re: No, C is not a simple language Kaz Kylheku <563-365-8930@kylheku.com> - 2021-04-20 20:18 +0000
Re: No, C is not a simple language Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-05-11 05:31 -0700
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-20 13:19 -0700
Re: No, C is not a simple language Kaz Kylheku <563-365-8930@kylheku.com> - 2021-04-20 20:29 +0000
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-20 13:39 -0700
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-20 14:29 -0700
Re: No, C is not a simple language Ian Collins <ian-news@hotmail.com> - 2021-04-21 08:56 +1200
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-20 14:07 -0700
Re: No, C is not a simple language jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-23 12:10 +0200
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 12:37 -0700
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 12:38 -0700
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 12:43 -0700
Re: No, C is not a simple language jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-23 22:38 +0200
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 13:44 -0700
Re: No, C is not a simple language Ian Collins <ian-news@hotmail.com> - 2021-04-24 10:56 +1200
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 16:09 -0700
Re: No, C is not a simple language Robert Latest <boblatest@yahoo.com> - 2021-04-26 09:30 +0000
Re: No, C is not a simple language Ian Collins <ian-news@hotmail.com> - 2021-04-30 21:11 +1200
Re: No, C is not a simple language Kaz Kylheku <563-365-8930@kylheku.com> - 2021-04-24 03:51 +0000
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-24 12:48 -0700
Re: No, C is not a simple language Robert Latest <boblatest@yahoo.com> - 2021-04-26 09:24 +0000
Re: No, C is not a simple language jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-26 21:24 +0200
Re: No, C is not a simple language Robert Latest <boblatest@yahoo.com> - 2021-04-27 07:26 +0000
Re: No, C is not a simple language Robert Latest <boblatest@yahoo.com> - 2021-04-26 09:27 +0000
Re: No, C is not a simple language "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2021-04-20 19:53 +0200
Re: No, C is not a simple language Thiago Adams <thiago.adams@gmail.com> - 2021-04-20 11:04 -0700
Re: No, C is not a simple language Robert Latest <boblatest@yahoo.com> - 2021-04-26 09:02 +0000
Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-26 09:43 +0000
Re: No, C is not a simple language Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2021-04-26 03:08 -0700
Re: No, C is not a simple language Robert Latest <boblatest@yahoo.com> - 2021-04-26 10:35 +0000
Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-26 13:08 +0000
Re: No, C is not a simple language Richard Damon <Richard@Damon-Family.org> - 2021-04-26 09:30 -0400
Re: No, C is not a simple language Robert Latest <boblatest@yahoo.com> - 2021-04-26 14:22 +0000
Re: No, C is not a simple language scott@slp53.sl.home (Scott Lurndal) - 2021-04-26 18:57 +0000
Re: No, C is not a simple language Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2021-04-26 06:55 -0700
Re: No, C is not a simple language Robert Latest <boblatest@yahoo.com> - 2021-04-26 14:15 +0000
Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-27 04:37 +0000
Re: No, C is not a simple language Robert Latest <boblatest@yahoo.com> - 2021-04-27 07:22 +0000
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-19 21:42 -0700
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-22 00:26 -0700
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-28 00:02 -0700
Page 4 of 5 — ← Prev page 1 2 3 [4] 5 Next page →
| From | jacobnavia <jacob@jacob.remcomp.fr> |
|---|---|
| Date | 2021-04-23 22:38 +0200 |
| Message-ID | <s5vb7n$n3o$1@dont-email.me> |
| In reply to | #160292 |
Le 23/04/2021 à 21:43, Chris M. Thomasson a écrit : > On 4/23/2021 12:37 PM, Chris M. Thomasson wrote: >> On 4/23/2021 3:10 AM, jacobnavia wrote: >>> Le 20/04/2021 à 23:07, Chris M. Thomasson a écrit : >>> >>>> >>>> For some reason, anytime I hear somebody go, just use a GC... Well, >>>> it makes think of this song: >>>> >>>> https://youtu.be/WJabPYimznY >>>> >>>> Or the following scene in Disney's Dragonslayer from 1981: >>>> >>>> https://youtu.be/TJRaLnLDMWg >>> >>> Great arguments! >>> >>> Technically sound, I am convinced now... >>> >>> >>> ... that you have nothing to say >> >> Have you ever had to deal with GC issues? I have... Unfortunately, >> some people seem to think that a full blown GC is okay to use for >> reclaiming memory in lock-free algorithms. It works, but can become a >> massive, nasty, unpredictable bottleneck. Only then do they complain. >> I warned some of them... >> >> https://youtu.be/XcxKIJTb3Hg >> > > I used to cringe when I would see code that would allocate nodes all > over the place, and never free them. Sometimes they would allocate nodes > in loops! They would say, ahhh, that's for the GC. WOW! Thanks for your reply, at least there are some real arguments and not that stupid links. As You seem to know, the GC can be misused, as anything can be misused. The GC is great in certain situations, not in others. I used it in my debugger. It was a GREAT relief to be able to allocate a piece of memory in the user interface, pass it to the debugger without caring about when and by whom it should be freed. Obviously the memory pieces being passed were user inputs,names of variables to be displayed,and many other SHORT pieces of memory. The other solution would bve to redesign the debugger and use a thread proof memory allocator that would keep the accounting,or other massive development projects. By using the GC I was able to concentrate ion the debugger itself, already a very complex program, and forget about the memory accounting chors. What is nice of the GC is the SIMPLIFICATION that provides. Of course it can be abused, as everything. Knives? Wondefful for cutting bread. But they can cut your fingers too. USE WITH CARE! GC is no differeent
[toc] | [prev] | [next] | [standalone]
| From | "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> |
|---|---|
| Date | 2021-04-23 13:44 -0700 |
| Message-ID | <s5vbjk$18ra$1@gioia.aioe.org> |
| In reply to | #160300 |
On 4/23/2021 1:38 PM, jacobnavia wrote: > Le 23/04/2021 à 21:43, Chris M. Thomasson a écrit : >> On 4/23/2021 12:37 PM, Chris M. Thomasson wrote: >>> On 4/23/2021 3:10 AM, jacobnavia wrote: >>>> Le 20/04/2021 à 23:07, Chris M. Thomasson a écrit : >>>> >>>>> >>>>> For some reason, anytime I hear somebody go, just use a GC... Well, >>>>> it makes think of this song: >>>>> >>>>> https://youtu.be/WJabPYimznY >>>>> >>>>> Or the following scene in Disney's Dragonslayer from 1981: >>>>> >>>>> https://youtu.be/TJRaLnLDMWg >>>> >>>> Great arguments! >>>> >>>> Technically sound, I am convinced now... >>>> >>>> >>>> ... that you have nothing to say >>> >>> Have you ever had to deal with GC issues? I have... Unfortunately, >>> some people seem to think that a full blown GC is okay to use for >>> reclaiming memory in lock-free algorithms. It works, but can become a >>> massive, nasty, unpredictable bottleneck. Only then do they complain. >>> I warned some of them... >>> >>> https://youtu.be/XcxKIJTb3Hg >>> >> >> I used to cringe when I would see code that would allocate nodes all >> over the place, and never free them. Sometimes they would allocate >> nodes in loops! They would say, ahhh, that's for the GC. WOW! > > Thanks for your reply, at least there are some real arguments and not > that stupid links. > > As You seem to know, the GC can be misused, as anything can be misused. > The GC is great in certain situations, not in others. Okay, that is fair enough. From my experience, GC it not okay to use in high pressure scenarios, under lots of load. It can cause all sorts of issues. > I used it in my debugger. It was a GREAT relief to be able to allocate a > piece of memory in the user interface, pass it to the debugger without > caring about when and by whom it should be freed. Obviously the memory > pieces being passed were user inputs,names of variables to be > displayed,and many other SHORT pieces of memory. The other solution > would bve to redesign the debugger and use a thread proof memory > allocator that would keep the accounting,or other massive development > projects. > > By using the GC I was able to concentrate ion the debugger itself, > already a very complex program, and forget about the memory accounting > chors. > > What is nice of the GC is the SIMPLIFICATION that provides. Of course it > can be abused, as everything. > > Knives? Wondefful for cutting bread. But they can cut your fingers too. > > USE WITH CARE! > > GC is no differeent Just, try not to use a GC as a crutch: The way of all things. Btw, some people say C is too dangerous to use, GC or not... Its as if they want people to be forced to put corks on their forks to prevent themselves from hurting themselves. https://youtu.be/SKDX-qJaJ08 lol.
[toc] | [prev] | [next] | [standalone]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2021-04-24 10:56 +1200 |
| Message-ID | <ieh1kuFb7j0U1@mid.individual.net> |
| In reply to | #160300 |
On 24/04/2021 08:38, jacobnavia wrote: > > By using the GC I was able to concentrate ion the debugger itself, > already a very complex program, and forget about the memory accounting > chors. > > What is nice of the GC is the SIMPLIFICATION that provides. Of course it > can be abused, as everything. We could use exactly the same argument for RAII and in the context of this thread, std::string. We could also add deterministic behaviour as a significant advantage RAII has over GC, especially in the semi-real time embedded world where much of today's C and C++ is written. > Knives? Wondefful for cutting bread. But they can cut your fingers too. > > USE WITH CARE! > > GC is no differeent Very true. GC can be a survivor when working with old, leaky, C code. I have deployed it with long running services that would run out of memory and die. It not only kept the thing running, but that particular library kept logs which could be used to find and fix the worst leaks. I have yet to use abetter tool for this job. -- Ian.
[toc] | [prev] | [next] | [standalone]
| From | "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> |
|---|---|
| Date | 2021-04-23 16:09 -0700 |
| Message-ID | <s5vk2g$jij$1@gioia.aioe.org> |
| In reply to | #160314 |
On 4/23/2021 3:56 PM, Ian Collins wrote: > On 24/04/2021 08:38, jacobnavia wrote: >> >> By using the GC I was able to concentrate ion the debugger itself, >> already a very complex program, and forget about the memory accounting >> chors. >> >> What is nice of the GC is the SIMPLIFICATION that provides. Of course it >> can be abused, as everything. > > We could use exactly the same argument for RAII and in the context of > this thread, std::string. We could also add deterministic behaviour as > a significant advantage RAII has over GC, especially in the semi-real > time embedded world where much of today's C and C++ is written. > > >> Knives? Wondefful for cutting bread. But they can cut your fingers too. >> >> USE WITH CARE! >> >> GC is no differeent > > > Very true. > > > GC can be a survivor when working with old, leaky, C code. I have > deployed it with long running services that would run out of memory and > die. It not only kept the thing running, but that particular library > kept logs which could be used to find and fix the worst leaks. I have > yet to use abetter tool for this job. > Yeah, I don't think I ever used GC for that, but it sure should help out indeed. Good one! :^) I while back, have had to find a find a horrible race-condition that would sometimes miss a call to free. So, sometimes, under certain conditions, the memory could grow out of control. It was a bitch and a half to debug. Iirc, it was a strange reference counting error that would not allow some things to be destroyed, so they would just hang around... I also remember debugging something that would hang up, from time to time. Iirc, the problem was that a mutex was not being unlocked under certain conditions. This was easier to fix than the previous one. The system would deadlock, and then I could go in and debug it in an actual deadlocked state.
[toc] | [prev] | [next] | [standalone]
| From | Robert Latest <boblatest@yahoo.com> |
|---|---|
| Date | 2021-04-26 09:30 +0000 |
| Message-ID | <ienfh3Fi7m1U11@mid.individual.net> |
| In reply to | #160314 |
Ian Collins wrote: > GC can be a survivor when working with old, leaky, C code. I have > deployed it with long running services that would run out of memory and > die. It not only kept the thing running, but that particular library > kept logs which could be used to find and fix the worst leaks. I have > yet to use abetter tool for this job. Valgrind? -- robert
[toc] | [prev] | [next] | [standalone]
| From | Ian Collins <ian-news@hotmail.com> |
|---|---|
| Date | 2021-04-30 21:11 +1200 |
| Message-ID | <if1vudF4bgtU1@mid.individual.net> |
| In reply to | #160348 |
On 26/04/2021 21:30, Robert Latest wrote: > Ian Collins wrote: >> GC can be a survivor when working with old, leaky, C code. I have >> deployed it with long running services that would run out of memory and >> die. It not only kept the thing running, but that particular library >> kept logs which could be used to find and fix the worst leaks. I have >> yet to use abetter tool for this job. > > Valgrind? A tool I use today, but but not one I would use on a production system without helium cooling! -- Ian.
[toc] | [prev] | [next] | [standalone]
| From | Kaz Kylheku <563-365-8930@kylheku.com> |
|---|---|
| Date | 2021-04-24 03:51 +0000 |
| Message-ID | <20210423204204.51@kylheku.com> |
| In reply to | #160292 |
["Followup-To:" header set to comp.lang.c.]
On 2021-04-23, Chris M. Thomasson <chris.m.thomasson.1@gmail.com> wrote:
> On 4/23/2021 12:37 PM, Chris M. Thomasson wrote:
>> On 4/23/2021 3:10 AM, jacobnavia wrote:
>>> Le 20/04/2021 à 23:07, Chris M. Thomasson a écrit :
>>>
>>>>
>>>> For some reason, anytime I hear somebody go, just use a GC... Well,
>>>> it makes think of this song:
>>>>
>>>> https://youtu.be/WJabPYimznY
>>>>
>>>> Or the following scene in Disney's Dragonslayer from 1981:
>>>>
>>>> https://youtu.be/TJRaLnLDMWg
>>>
>>> Great arguments!
>>>
>>> Technically sound, I am convinced now...
>>>
>>>
>>> ... that you have nothing to say
>>
>> Have you ever had to deal with GC issues? I have... Unfortunately, some
>> people seem to think that a full blown GC is okay to use for reclaiming
>> memory in lock-free algorithms. It works, but can become a massive,
>> nasty, unpredictable bottleneck. Only then do they complain. I warned
>> some of them...
>>
>> https://youtu.be/XcxKIJTb3Hg
>>
>
> I used to cringe when I would see code that would allocate nodes all
> over the place, and never free them. Sometimes they would allocate nodes
> in loops! They would say, ahhh, that's for the GC. WOW!
Allocating a node in the loop such that it is unreachable is actually a
pretty easy situation for GC.
(while true
(cons x y))
The cons cell is allocated and immediately becomes unreachable. Being
unreachable it means that when GC is triggered, it does not have to
traverse it.
Traversing the graph of reachable objects is a big expense.
It will have to sweep these cons cells to reclaim them. But that would
have to be done by explicit memory management also!
Sweeping can be a big expense in a naive mark-and-sweep allocator.
A generational garbage collector, though, makes the sweep cheaper.
A generational garbage collector will allocate these new cells into
a "nursery" of baby objects.
When a certain limit is reached, a generational GC pass is triggered.
The GC walks the object graph, but it avoids traversing across "mature"
objects; it looks at areas like the machine registers and stack, looking
only for baby objects. It will not find any of these baby objects
because only the loop is creating them, and it loses track of each one.
Then comes the generational sweep phase. Unlike in a full GC pass,
the garbage collector only has to sweep through the nursery. The nursery
is chock full of these cons cells made in the body of the loop. None
of them were marked reachable, so they are deallocated.
This sweep pass does not have to look at any mature objects at all.
Basically, GC can be designed and tuned to deal with the pressure of a
fast allocation of temporary objects that soon become garbage.
Such cases arise in practical applications. For instance, macro
expansion in Lisp. Or string processing. Or calculations with numbers
that have to be boxed on the heap, like bignums and sometimes
floating-point values.
--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
[toc] | [prev] | [next] | [standalone]
| From | "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> |
|---|---|
| Date | 2021-04-24 12:48 -0700 |
| Message-ID | <s61slo$18a3$1@gioia.aioe.org> |
| In reply to | #160319 |
On 4/23/2021 8:51 PM, Kaz Kylheku wrote: > ["Followup-To:" header set to comp.lang.c.] > On 2021-04-23, Chris M. Thomasson <chris.m.thomasson.1@gmail.com> wrote: >> On 4/23/2021 12:37 PM, Chris M. Thomasson wrote: >>> On 4/23/2021 3:10 AM, jacobnavia wrote: >>>> Le 20/04/2021 à 23:07, Chris M. Thomasson a écrit : >>>> >>>>> >>>>> For some reason, anytime I hear somebody go, just use a GC... Well, >>>>> it makes think of this song: >>>>> >>>>> https://youtu.be/WJabPYimznY >>>>> >>>>> Or the following scene in Disney's Dragonslayer from 1981: >>>>> >>>>> https://youtu.be/TJRaLnLDMWg >>>> >>>> Great arguments! >>>> >>>> Technically sound, I am convinced now... >>>> >>>> >>>> ... that you have nothing to say >>> >>> Have you ever had to deal with GC issues? I have... Unfortunately, some >>> people seem to think that a full blown GC is okay to use for reclaiming >>> memory in lock-free algorithms. It works, but can become a massive, >>> nasty, unpredictable bottleneck. Only then do they complain. I warned >>> some of them... >>> >>> https://youtu.be/XcxKIJTb3Hg >>> >> >> I used to cringe when I would see code that would allocate nodes all >> over the place, and never free them. Sometimes they would allocate nodes >> in loops! They would say, ahhh, that's for the GC. WOW! > > Allocating a node in the loop such that it is unreachable is actually a > pretty easy situation for GC. Ahhh yes. But I failed to give more context Kaz, sorry! Basically, the loop would receive events from observer threads, and create responses via allocating new nodes and pushing them into lock-free queues. The problem was that the frequency of this event loop would get "hot", and end up creating a shi% load of new nodes, not a free in sight. The GC would get radically loaded up. > > (while true > (cons x y)) > > The cons cell is allocated and immediately becomes unreachable. Being > unreachable it means that when GC is triggered, it does not have to > traverse it. > > Traversing the graph of reachable objects is a big expense. > > It will have to sweep these cons cells to reclaim them. But that would > have to be done by explicit memory management also! > > Sweeping can be a big expense in a naive mark-and-sweep allocator. > A generational garbage collector, though, makes the sweep cheaper. > > A generational garbage collector will allocate these new cells into > a "nursery" of baby objects. > > When a certain limit is reached, a generational GC pass is triggered. > The GC walks the object graph, but it avoids traversing across "mature" > objects; it looks at areas like the machine registers and stack, looking > only for baby objects. It will not find any of these baby objects > because only the loop is creating them, and it loses track of each one. > > Then comes the generational sweep phase. Unlike in a full GC pass, > the garbage collector only has to sweep through the nursery. The nursery > is chock full of these cons cells made in the body of the loop. None > of them were marked reachable, so they are deallocated. > > This sweep pass does not have to look at any mature objects at all. > > Basically, GC can be designed and tuned to deal with the pressure of a > fast allocation of temporary objects that soon become garbage. > Such cases arise in practical applications. For instance, macro > expansion in Lisp. Or string processing. Or calculations with numbers > that have to be boxed on the heap, like bignums and sometimes > floating-point values. >
[toc] | [prev] | [next] | [standalone]
| From | Robert Latest <boblatest@yahoo.com> |
|---|---|
| Date | 2021-04-26 09:24 +0000 |
| Message-ID | <ienf7bFi7m1U9@mid.individual.net> |
| In reply to | #160245 |
["Followup-To:" header set to comp.lang.c.] jacobnavia wrote: > Just have a constructotr and never free anything. Then link with Boehm's > GARBAGE COLLECTOR and be done with it! Whan I find myself in a situation where explicitly freeing resources becomes unwieldy I start thinking about using another language than C (which, like i.e. Python, comes with garage collection). If you're too lazy to use free(), you should also be too lazy to use malloc() or to declare your variables. Better to use a language where you don't have to do any of it. -- robert
[toc] | [prev] | [next] | [standalone]
| From | jacobnavia <jacob@jacob.remcomp.fr> |
|---|---|
| Date | 2021-04-26 21:24 +0200 |
| Message-ID | <s6740v$g4c$1@dont-email.me> |
| In reply to | #160346 |
Le 26/04/2021 à 11:24, Robert Latest a écrit : > ["Followup-To:" header set to comp.lang.c.] > jacobnavia wrote: >> Just have a constructotr and never free anything. Then link with Boehm's >> GARBAGE COLLECTOR and be done with it! > > Whan I find myself in a situation where explicitly freeing resources becomes > unwieldy I start thinking about using another language than C (which, like > i.e. Python, comes with garage collection). > > If you're too lazy to use free(), you should also be too lazy to use malloc() > or to declare your variables. Better to use a language where you don't have to > do any of it. > I used the GC extensively in my debugger and in the IDE for lcc-win. The IDE must receive user inputs and pass them to the debugger, the debugger must receive them and then use them during a certain time, for instance when displaying info for the current line. When the user gose to the next line, the debugger should free all the allocations done for that line and prepare the display for the one that the IDE says the program stopped. This back and forth can be solved with several heaps, a heap for each line, etc. That would solve that problem but the rest of the problems would need also other allocations and freeing, etc. The debugger and the IDE run in different threads, and the user program runs in yet another thread. Look, of course I am a lazy guy, I am alone developing all that, and , due to my laziness, I like solutions THAT WORK WITHOUT TOO MUCH EFFORT! And no, I will not change the language to write a low level debugger in python (imagine that)
[toc] | [prev] | [next] | [standalone]
| From | Robert Latest <boblatest@yahoo.com> |
|---|---|
| Date | 2021-04-27 07:26 +0000 |
| Message-ID | <iepsl9F3s1nU2@mid.individual.net> |
| In reply to | #160367 |
jacobnavia wrote: > I used the GC extensively in my debugger and in the IDE for lcc-win. I'm not sying a GC is always a bad idea. But many of the arguments go along the lines "C is a bad language because I have to clean up after myself." That part I don't agree with, especially because it tends to come from people who don't have much experience in C. -- robert
[toc] | [prev] | [next] | [standalone]
| From | Robert Latest <boblatest@yahoo.com> |
|---|---|
| Date | 2021-04-26 09:27 +0000 |
| Message-ID | <ienfctFi7m1U10@mid.individual.net> |
| In reply to | #160245 |
["Followup-To:" header set to comp.lang.c.] jacobnavia wrote: > I use an automatic car, no passing of gears. Recently I spoke with a > taxi driver... "Don't you get bored passing gears all day?" > > And he acknowledged: yes, My arm hurts at the end of the day. Maybe you > are right, should get an automatic... The C-with-GC analogy would be to first buy a stick shift car and then expensively retrofit it with an automatic transmiassion (probably voiding the warranty in the process). Better to buy a car that already comes with automatic transmission. -- robert
[toc] | [prev] | [next] | [standalone]
| From | "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> |
|---|---|
| Date | 2021-04-20 19:53 +0200 |
| Message-ID | <s5n4e0$itg$1@dont-email.me> |
| In reply to | #160244 |
On 20.04.2021 18:41, Juha Nieminen wrote: > In comp.lang.c++ Manfred <noname@add.invalid> wrote: >> Anything that happens behind the scenes and the compiler "does it for >> you" does require knowledge by the programmer about something they don't >> see and yet they must be aware of and know how it works. >> And yes, they are intended to (and actually do) make life easier for the >> programmer /after/ they master their mechanics, but a beginner's mistake >> related with such hidden features is likely to lead to somewhat >> shady/obscure bugs - i.e. hard for said beginner. > > The problem with C is that anything that requires manual construction and > destruction will "contaminate" (can't think of a better word) anything that > uses that first thing, with the same requirements. All the way down. > > If you have this kind of "string" object that requires manual construction > and destruction, and you put it as a member of a struct, suddenly that > struct "inherits" the same requirement. Use that struct in yet another > struct and that, too, will "inherit" the same requirement. > > Moreover, suppose you have a complex hierarchy of structs as members of > other structs, no dynamic memory allocation in sight so far. Then you need > to add dynamic memory allocation to one of the structs (that's being used > as a member of other structs etc) and suddenly all that code breaks. If > there are millions of lines of code using any of those structs that have > now "inherited" the need for manual construction and destruction (even though > they were never designed for that initially), you'll have to go and modify > those millions of lines to follow suit. Very good points. In addition, what C++ provides as built-in language features, has to be supplied as 3d party library or DIY functionality in C. That means that in C * one can't leverage a single knowledge base, but must learn each support library that's needed for those C++ features, and * the compiler can't be fine tuned to a particular implementation. > The complexity can quickly grow exponentially. Not sure about that though, but that it grows, yes. > Not so in C++, if you design your structs/classes correctly. Even if some > struct/class very deep in the dependency tree suddenly starts allocating > memory dynamically, that doesn't matter. None of the other structs/classes > that may be using it as their members need to be touched in any way. The > struct/class automatically takes care of its own memory management. You > don't need to go through the millions of lines of code to add support. > >> On a different perspective, consider e.g. rvalue refs and "universal" >> refs (in Meyers' terms) - they make a useful feature, but good luck >> explaining it to said beginner. > > I wouldn't teach function and array pointers as a first thing to a beginner. > Likewise I wouldn't teach rvalue references as a first thing. The "Accelerated C++" book by Andrew Koenig and Barbara Mooooooooo showed that the high level approach can really work for C++. But I think that for these fundamental aspects of programming, if one desires to teach at a high level of abstraction then some other language will be better suited. I'm thinking C# (which I known from the "classic" C# days) or, say, Rust (which I don't know beyond "Hello, world!"). A nice feature of C++ is that it's /possible/ to teach programming in a mixed way, introducing the low level stuff but using containers, strings etc. It's sad that C++ still lacks standard 128-bit integers and ditto currency type; still lacks datetime type; still lacks a practically usable for beginners version of `std::ranges::views::iota` (I prefer to define things so one can write e.g. `for( const int i: zero_to( n ) )`; not to mention that the common /C++ implementations/ for Windows still lack support for UTF-8, both in console and GUI programs, so that learners can't even write a program that displays their non-English name in Windows without using 3rd party libraries or the Windows API. That's just basic functionality. Try motivating a leaner by coding up the (recursive) C curve in standard C++ only. Oh, no graphics. Oh well. So, as I see it standard C++ in itself is not good for learners, but it can be good with the right 3rd party libraries. I guess you all know that I've been hobby-working on libraries to fill the mentioned data type and console i/o voids, and that I've found that it decidedly is a non-trivial design task (which may be part of the reason why such libraries don't already exists). And perhaps the good Mr. Fibble's Neo-something could help with the graphics and sound aspects. - Alf
[toc] | [prev] | [next] | [standalone]
| From | Thiago Adams <thiago.adams@gmail.com> |
|---|---|
| Date | 2021-04-20 11:04 -0700 |
| Message-ID | <64bb1629-67b7-48b6-a1c0-6cda34bce7c0n@googlegroups.com> |
| In reply to | #160244 |
On Tuesday, April 20, 2021 at 1:41:41 PM UTC-3, Juha Nieminen wrote:
> In comp.lang.c++ Manfred <non...@add.invalid> wrote:
> > Anything that happens behind the scenes and the compiler "does it for
> > you" does require knowledge by the programmer about something they don't
> > see and yet they must be aware of and know how it works.
> > And yes, they are intended to (and actually do) make life easier for the
> > programmer /after/ they master their mechanics, but a beginner's mistake
> > related with such hidden features is likely to lead to somewhat
> > shady/obscure bugs - i.e. hard for said beginner.
> The problem with C is that anything that requires manual construction and
> destruction will "contaminate" (can't think of a better word) anything that
> uses that first thing, with the same requirements. All the way down.
> If you have this kind of "string" object that requires manual construction
> and destruction, and you put it as a member of a struct, suddenly that
> struct "inherits" the same requirement. Use that struct in yet another
> struct and that, too, will "inherit" the same requirement.
>
> Moreover, suppose you have a complex hierarchy of structs as members of
> other structs, no dynamic memory allocation in sight so far. Then you need
> to add dynamic memory allocation to one of the structs (that's being used
> as a member of other structs etc) and suddenly all that code breaks. If
> there are millions of lines of code using any of those structs that have
> now "inherited" the need for manual construction and destruction (even though
> they were never designed for that initially), you'll have to go and modify
> those millions of lines to follow suit.
To avoid this contamination for **constructors** in C use an static initialization.
For instance:
struct Person { char* name; }
struct House { struct Person person; }
struct House house = {0}; //this constructor does not change
For destructor it is not so easy... My suggestion for C is to
create destructors and "auto" pointers.
Then this would be the required code if C had this feature.
struct Person { char auto* name; }
struct House { struct Person person; }
struct House house = {0};
destroy(house);
> The complexity can quickly grow exponentially.
Yes. People talk about RAII but this specific code generation
is important.
[toc] | [prev] | [next] | [standalone]
| From | Robert Latest <boblatest@yahoo.com> |
|---|---|
| Date | 2021-04-26 09:02 +0000 |
| Message-ID | <iendscFi7m1U8@mid.individual.net> |
| In reply to | #160244 |
["Followup-To:" header set to comp.lang.c.] Juha Nieminen wrote: > The problem with C is that anything that requires manual construction and > destruction will "contaminate" (can't think of a better word) anything that > uses that first thing, with the same requirements. All the way down. Of course it does. If you insist on doing it in C, it's best to define functions new_xxx and free_xxx for each type xxx, and make sure that free_yyy is called from free_xxx if the xxx type contains dynamically allocated objects of type yyy. It's really not hard, just requires a bit of typing, but it's a tremendously helpful exercise especially for a beginner. BTW if this concept is new or "The problem" for you, I don't believe you have much experience with C. > If you have this kind of "string" object that requires manual construction > and destruction, and you put it as a member of a struct, suddenly that > struct "inherits" the same requirement. Use that struct in yet another > struct and that, too, will "inherit" the same requirement. Trivially dealt with, see above. > Moreover, suppose you have a complex hierarchy of structs as members of > other structs, no dynamic memory allocation in sight so far. Then you need > to add dynamic memory allocation to one of the structs (that's being used > as a member of other structs etc) and suddenly all that code breaks. ...as it would in any language if you change the architecture of your design without making the appropriate changes where needed. > If > there are millions of lines of code using any of those structs that have > now "inherited" the need for manual construction and destruction (even though > they were never designed for that initially), you'll have to go and modify > those millions of lines to follow suit. If that's a problem for you, just don't use a strongly typed language. > Not so in C++, if you design your structs/classes correctly. Your argument above is based on NOT designing your data structures correctly in C, and now you say C++ handles better but only IF you do it correctly? Doesn't make sense. Even when trying to do everything explicitly right in C you will make mistakes. Or I will, anyway. I've found valgrind to be an invaluable tool when debugging C code. I'm very happy with teaming up C and Python. Low level ultrafast stuff in C extension, high level OO garbage-collected stuff in Python. In the 90's I did a largish project in C++ and never grew to like it much. -- robert
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2021-04-26 09:43 +0000 |
| Message-ID | <s661v4$102q$1@gioia.aioe.org> |
| In reply to | #160345 |
In comp.lang.c++ Robert Latest <boblatest@yahoo.com> wrote: > Your argument above is based on NOT designing your data structures correctly in > C, and now you say C++ handles better but only IF you do it correctly? Doesn't > make sense. Are you telling be that every single time you create a struct in a C program you always write a "constructor" and "destructor" for it, just in case that some time in the future they might start requiring them? Well, even if you actually do, my point stands: In C++ you don't need to do that.
[toc] | [prev] | [next] | [standalone]
| From | Malcolm McLean <malcolm.arthur.mclean@gmail.com> |
|---|---|
| Date | 2021-04-26 03:08 -0700 |
| Message-ID | <cc74cfb8-49e6-438f-b22c-73aca398f90fn@googlegroups.com> |
| In reply to | #160349 |
On Monday, 26 April 2021 at 10:43:14 UTC+1, Juha Nieminen wrote: > In comp.lang.c++ Robert Latest <bobl...@yahoo.com> wrote: > > Your argument above is based on NOT designing your data structures correctly in > > C, and now you say C++ handles better but only IF you do it correctly? Doesn't > > make sense. > Are you telling be that every single time you create a struct in a C program > you always write a "constructor" and "destructor" for it, just in case that > some time in the future they might start requiring them? > > Well, even if you actually do, my point stands: In C++ you don't need to do > that. > You operate at a sligly higher level than that. A "struct point" wouldn't have a constructor / destructor pair. But if a structure is either "open" enough that it might be extended to contain other embedded pointers, e.g. a "struct employee" with char *name field might well acquire other string fields as the program develops, or if it is sufficiently complicated to justify opaque operations, then it would routinely have a constructor / destructor pair. In C++, as long as you use stl, destruction is done for you, and you can also move between putting objects on the heap or on the stack smoothly. C++ is better in this regard. However it's not usually a huge deal - the pattern is that you create the object on the heap, you pass it about as an opaque pointer and manipulate it with functions defined in its object defintion file, then when you are done with it you call the destructor. It's all routine programming.
[toc] | [prev] | [next] | [standalone]
| From | Robert Latest <boblatest@yahoo.com> |
|---|---|
| Date | 2021-04-26 10:35 +0000 |
| Message-ID | <ienjanFl5j5U1@mid.individual.net> |
| In reply to | #160349 |
["Followup-To:" header set to comp.lang.c.] Juha Nieminen wrote: > In comp.lang.c++ Robert Latest <boblatest@yahoo.com> wrote: >> Your argument above is based on NOT designing your data structures correctly >> in C, and now you say C++ handles better but only IF you do it correctly? >> Doesn't make sense. > > Are you telling be that every single time you create a struct in a C program > you always write a "constructor" and "destructor" for it, Of course not. > just in case that some time in the future they might start requiring them? No. Only if the data structure requires it, as is typical with nested, dynamically allocated structs. Then of course it requires only a few extra lines of code per struct type. If your struct is used for any non-trivial amount of work you'll need some init code anyway. > Well, even if you actually do, my point stands: In C++ you don't need to do > that. Then why don't you use C++ if thinking about memory management bothers you so much? -- robert
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2021-04-26 13:08 +0000 |
| Message-ID | <s66dvh$1dj2$1@gioia.aioe.org> |
| In reply to | #160352 |
In comp.lang.c++ Robert Latest <boblatest@yahoo.com> wrote: > ["Followup-To:" header set to comp.lang.c.] > Juha Nieminen wrote: >> In comp.lang.c++ Robert Latest <boblatest@yahoo.com> wrote: >>> Your argument above is based on NOT designing your data structures correctly >>> in C, and now you say C++ handles better but only IF you do it correctly? >>> Doesn't make sense. >> >> Are you telling be that every single time you create a struct in a C program >> you always write a "constructor" and "destructor" for it, > > Of course not. That's exactly my point: Suppose you have a huge amount of code, with lots and lots of structs, structs as members of other structs, and a lot of code that uses those structs. Then one day you decide to add a dynamically allocated array (such as a dynamically allocated string) to one of the structs, which is used in lots of other structs, which themselves are used in other structs, and so on... Because of a chance in this one struct, suddenly lots of other structs "inherit" its need for manual construction and destruction, and tons of code that uses those other structs need to be refactored to now call the constructors and destructors of all the structs that now require it. All because of this one struct. In C++, you don't have to. You just add the dynamic data structure to that one struct, and you're done. No need to modify anything else. >> Well, even if you actually do, my point stands: In C++ you don't need to do >> that. > Then why don't you use C++ if thinking about memory management bothers you so > much? That's exactly what I do, whenever I can.
[toc] | [prev] | [next] | [standalone]
| From | Richard Damon <Richard@Damon-Family.org> |
|---|---|
| Date | 2021-04-26 09:30 -0400 |
| Message-ID | <dgzhI.147872$PE7.113157@fx39.iad> |
| In reply to | #160355 |
On 4/26/21 9:08 AM, Juha Nieminen wrote: > In comp.lang.c++ Robert Latest <boblatest@yahoo.com> wrote: >> ["Followup-To:" header set to comp.lang.c.] >> Juha Nieminen wrote: >>> In comp.lang.c++ Robert Latest <boblatest@yahoo.com> wrote: >>>> Your argument above is based on NOT designing your data structures correctly >>>> in C, and now you say C++ handles better but only IF you do it correctly? >>>> Doesn't make sense. >>> >>> Are you telling be that every single time you create a struct in a C program >>> you always write a "constructor" and "destructor" for it, >> >> Of course not. > > That's exactly my point: > > Suppose you have a huge amount of code, with lots and lots of structs, structs > as members of other structs, and a lot of code that uses those structs. > > Then one day you decide to add a dynamically allocated array (such as a > dynamically allocated string) to one of the structs, which is used in > lots of other structs, which themselves are used in other structs, and > so on... > > Because of a chance in this one struct, suddenly lots of other structs > "inherit" its need for manual construction and destruction, and tons of > code that uses those other structs need to be refactored to now call the > constructors and destructors of all the structs that now require it. > All because of this one struct. > > In C++, you don't have to. You just add the dynamic data structure to > that one struct, and you're done. No need to modify anything else. > >>> Well, even if you actually do, my point stands: In C++ you don't need to do >>> that. > >> Then why don't you use C++ if thinking about memory management bothers you so >> much? > > That's exactly what I do, whenever I can. > Yes, in C if you make that sort of change, you need to change a lot of code. That is also, if you really think about it, a major breaking change in the definition of the struct. BECAUSE in C, you need to manual handle allocation, this is a breaking API change to a structure from DEFINED to not need management, to needing management. In C, you need to think ahead and ask if you can conceive of a need to manage the life of the structure, and if so add explicit create/destroy methods, even if for now, they do nothing. (You can make them in-liene no-ops so can be no cost. Yes, that is one of the advantages of C++, that you can easily change this as C++ will automatically make this change for you. It also can be seen as a weakness. It can be easy to make an apparently innocent looking change that affects the performance of wide swathes of code as that code get replicated everywhere.
[toc] | [prev] | [next] | [standalone]
Page 4 of 5 — ← Prev page 1 2 3 [4] 5 Next page →
Back to top | Article view | comp.lang.c
csiph-web