Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #79175 > unrolled thread
| Started by | jacobnavia <jacob@jacob.remcomp.fr> |
|---|---|
| First post | 2021-04-22 18:58 +0200 |
| Last post | 2021-04-26 18:04 +0200 |
| Articles | 20 on this page of 96 — 27 participants |
Back to article view | Back to comp.lang.c++
Text editor project in C jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-22 18:58 +0200
Re: Text editor project in C Bonita Montero <Bonita.Montero@gmail.com> - 2021-04-22 19:05 +0200
Re: Text editor project in C wij <wyniijj@gmail.com> - 2021-04-22 12:41 -0700
Re: Text editor project in C Juha Nieminen <nospam@thanks.invalid> - 2021-04-23 07:38 +0000
Re: Text editor project in C wij <wyniijj@gmail.com> - 2021-04-23 05:12 -0700
Re: Text editor project in C red floyd <myob@its.invalid> - 2021-04-23 09:24 -0700
Re: Text editor project in C James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-04-23 16:59 -0400
Re: Text editor project in C wij <wyniijj@gmail.com> - 2021-04-23 21:43 -0700
Re: Text editor project in C Ian Collins <ian-news@hotmail.com> - 2021-04-24 17:05 +1200
Re: Text editor project in C wij <wyniijj@gmail.com> - 2021-04-24 00:50 -0700
Re: Text editor project in C "daniel...@gmail.com" <danielaparker@gmail.com> - 2021-04-24 08:50 -0700
Re: Text editor project in C wij <wyniijj@gmail.com> - 2021-04-24 10:41 -0700
Re: Text editor project in C Öö Tiib <ootiib@hot.ee> - 2021-04-25 06:19 -0700
Re: Text editor project in C wij <wyniijj@gmail.com> - 2021-04-25 10:23 -0700
Re: Text editor project in C Öö Tiib <ootiib@hot.ee> - 2021-04-25 12:46 -0700
Re: Text editor project in C wij <wyniijj@gmail.com> - 2021-04-25 20:34 -0700
Re: Text editor project in C Öö Tiib <ootiib@hot.ee> - 2021-04-28 09:57 -0700
Re: Text editor project in C wij <wyniijj@gmail.com> - 2021-04-29 10:56 -0700
Re: Text editor project in C jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-27 18:31 +0200
Re: Text editor project in C David Brown <david.brown@hesbynett.no> - 2021-04-28 09:01 +0200
Re: Text editor project in C Manfred <noname@add.invalid> - 2021-04-28 14:54 +0200
Re: Text editor project in C Juha Nieminen <nospam@thanks.invalid> - 2021-04-29 04:47 +0000
Re: Text editor project in C Paavo Helde <myfirstname@osa.pri.ee> - 2021-04-29 11:42 +0300
Re: Text editor project in C Christian Gollwitzer <auriocus@gmx.de> - 2021-04-29 23:04 +0200
Re: Text editor project in C Juha Nieminen <nospam@thanks.invalid> - 2021-04-23 07:55 +0000
Re: Text editor project in C jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-23 11:25 +0200
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 12:45 -0700
Re: Text editor project in C jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-23 22:29 +0200
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 13:34 -0700
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 13:37 -0700
Re: Text editor project in C jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-23 22:40 +0200
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 13:51 -0700
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 13:55 -0700
Re: Text editor project in C jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-23 23:02 +0200
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 14:13 -0700
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 15:39 -0700
Re: Text editor project in C Bart <bc@freeuk.com> - 2021-04-24 01:20 +0100
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 17:43 -0700
Re: Text editor project in C kegs@provalid.com (Kent Dickey) - 2021-04-25 00:04 -0500
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-24 22:29 -0700
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-24 23:05 -0700
Re: Text editor project in C Paavo Helde <myfirstname@osa.pri.ee> - 2021-04-25 10:57 +0300
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-25 01:18 -0700
Re: Text editor project in C Paavo Helde <myfirstname@osa.pri.ee> - 2021-04-25 11:28 +0300
Re: Text editor project in C James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-04-25 15:02 -0400
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-26 01:25 -0700
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-26 01:26 -0700
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 14:15 -0700
Re: Text editor project in C scott@slp53.sl.home (Scott Lurndal) - 2021-04-23 22:25 +0000
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 15:31 -0700
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 13:38 -0700
Re: Text editor project in C scott@slp53.sl.home (Scott Lurndal) - 2021-04-23 22:27 +0000
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 15:34 -0700
Re: Text editor project in C scott@slp53.sl.home (Scott Lurndal) - 2021-04-24 16:33 +0000
Re: Text editor project in C "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-24 22:59 -0700
Re: Text editor project in C Juha Nieminen <nospam@thanks.invalid> - 2021-04-26 05:22 +0000
Re: Text editor project in C jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-26 10:00 +0200
Re: Text editor project in C Juha Nieminen <nospam@thanks.invalid> - 2021-04-26 09:57 +0000
Re: Text editor project in C Robert Latest <boblatest@yahoo.com> - 2021-04-26 10:41 +0000
Re: Text editor project in C jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-26 13:20 +0200
Re: Text editor project in C Juha Nieminen <nospam@thanks.invalid> - 2021-04-26 13:17 +0000
Re: Text editor project in C jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-26 19:53 +0200
Re: Text editor project in C David Brown <david.brown@hesbynett.no> - 2021-04-26 20:34 +0200
Re: Text editor project in C jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-26 22:49 +0200
Re: Text editor project in C David Brown <david.brown@hesbynett.no> - 2021-04-27 10:59 +0200
Re: Text editor project in C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-04-26 22:04 +0100
Re: Text editor project in C Eli the Bearded <*@eli.users.panix.com> - 2021-04-26 22:19 +0000
Re: Text editor project in C Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-04-26 16:07 -0700
Re: Text editor project in C Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2021-04-26 17:08 -0600
Re: Text editor project in C Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-04-26 16:57 -0700
Re: Text editor project in C Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2021-04-26 21:42 -0600
Re: Text editor project in C Kaz Kylheku <563-365-8930@kylheku.com> - 2021-04-27 00:46 +0000
Re: Text editor project in C Juha Nieminen <nospam@thanks.invalid> - 2021-04-27 04:51 +0000
Re: Text editor project in C Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2021-04-27 10:03 -0600
Re: Text editor project in C Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-04-27 09:20 -0700
Re: Text editor project in C scott@slp53.sl.home (Scott Lurndal) - 2021-04-27 16:34 +0000
Re: Text editor project in C Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2021-04-27 10:55 -0600
Re: Text editor project in C Kaz Kylheku <563-365-8930@kylheku.com> - 2021-04-27 17:13 +0000
Re: Text editor project in C Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2021-04-27 17:28 +0000
Re: Text editor project in C Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-04-27 13:33 -0700
Re: Text editor project in C scott@slp53.sl.home (Scott Lurndal) - 2021-04-27 19:27 +0000
Re: Text editor project in C Kaz Kylheku <563-365-8930@kylheku.com> - 2021-04-27 17:11 +0000
Re: Text editor project in C scott@slp53.sl.home (Scott Lurndal) - 2021-04-27 14:28 +0000
Re: Text editor project in C Juha Nieminen <nospam@thanks.invalid> - 2021-04-27 15:11 +0000
Re: Text editor project in C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-04-26 21:37 +0100
Re: Text editor project in C jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-26 22:48 +0200
Re: Text editor project in C scott@slp53.sl.home (Scott Lurndal) - 2021-04-26 21:53 +0000
Re: Text editor project in C Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-04-27 01:34 +0100
Re: Text editor project in C Guillaume <message@bottle.org> - 2021-04-26 18:48 +0200
Re: Text editor project in C James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-04-26 13:54 -0400
Re: Text editor project in C Jorgen Grahn <grahn+nntp@snipabacken.se> - 2021-04-23 20:00 +0000
Re: Text editor project in C Juha Nieminen <nospam@thanks.invalid> - 2021-04-26 05:29 +0000
Re: Text editor project in C om@iki.fi (Otto J. Makela) - 2021-04-23 19:25 +0300
Re: Text editor project in C wij <wyniijj@gmail.com> - 2021-04-24 10:55 -0700
Re: Text editor project in C Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-04-24 14:21 -0700
Re: Text editor project in C Bonita Montero <Bonita.Montero@gmail.com> - 2021-04-26 18:04 +0200
Page 3 of 5 — ← Prev page 1 2 [3] 4 5 Next page →
| From | "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> |
|---|---|
| Date | 2021-04-24 23:05 -0700 |
| Message-ID | <s630rp$14a0$1@gioia.aioe.org> |
| In reply to | #79246 |
On 4/24/2021 10:04 PM, Kent Dickey wrote: > In article <s5vd9u$1um1$1@gioia.aioe.org>, > Chris M. Thomasson <chris.m.thomasson.1@gmail.com> wrote: >> On 4/23/2021 2:02 PM, jacobnavia wrote: >>> Le 23/04/2021 à 22:51, Chris M. Thomasson a écrit : >>>> On 4/23/2021 1:40 PM, jacobnavia wrote: >>>>> I explained to you why the code doesn't bother to free the >>>>> memorysince it is used for the whole time that the editor is running. >>>>> Freeing it just before exiting the program makes no sense. > > [ snip] > >> I know exactly what you are talking about. However, please clean up >> after yourself? Pretty please? UNIX is not the only system out there. >> This is a bad habit to get into. Clean up, gosh darn it. > > First: Programs do need to erase any temp files and free any shared > resources. > > I wouldn't have really cared about matching malloc()/free() as an issue, but > I have a problem with a program trying to free() all of its memory when > qutting that is causing a problem itself. > > 1) It allocates shared memory segments. If they already exist, an error is > printed which does not in any way explain the problem. > 2) It does millions of malloc()'s (or their equivalent, like many programs now, > it's written in at least 4 languages). > 3) I try to exit the program. > 4) While walking it's crazy internal structures, to simply call free(), it > finds an inconsistency and immediately exits. > 5) It forgets to free the shared memory segments since that would be done > after the consistency check. > > If you try to re-run the program now, it may fail due to the shared memory > segments still existing. > > The problem is at no point does the code really care about these internal > consistency checks--except when it wants to exit. And it's deemed not a > real problem since the program does exit (with an error code). > > If the code simply freed the shared memory segments and did exit(0), and > didn't try to balance malloc() and free(), it would just work. > > There's a great deal of complexity unwinding complex malloc() chains, and > why bother debugging that mess? Yes, memory leaks are bad, but allocations > that will never be freed are not a problem. Every OS (even trivial ones) > can handle programs not calling free() when the program exits. > Have you ever messed around with Reaps? https://people.cs.umass.edu/~emery/pubs/berger-oopsla2002.pdf
[toc] | [prev] | [next] | [standalone]
| From | Paavo Helde <myfirstname@osa.pri.ee> |
|---|---|
| Date | 2021-04-25 10:57 +0300 |
| Message-ID | <s637ck$u2k$1@dont-email.me> |
| In reply to | #79246 |
25.04.2021 08:04 Kent Dickey kirjutas: > In article <s5vd9u$1um1$1@gioia.aioe.org>, > Chris M. Thomasson <chris.m.thomasson.1@gmail.com> wrote: >> On 4/23/2021 2:02 PM, jacobnavia wrote: >>> Le 23/04/2021 à 22:51, Chris M. Thomasson a écrit : >>>> On 4/23/2021 1:40 PM, jacobnavia wrote: >>>>> I explained to you why the code doesn't bother to free the >>>>> memorysince it is used for the whole time that the editor is running. >>>>> Freeing it just before exiting the program makes no sense. > > [ snip] > >> I know exactly what you are talking about. However, please clean up >> after yourself? Pretty please? UNIX is not the only system out there. >> This is a bad habit to get into. Clean up, gosh darn it. > > First: Programs do need to erase any temp files and free any shared > resources. > > I wouldn't have really cared about matching malloc()/free() as an issue, but > I have a problem with a program trying to free() all of its memory when > qutting that is causing a problem itself. > > 1) It allocates shared memory segments. If they already exist, an error is > printed which does not in any way explain the problem. > 2) It does millions of malloc()'s (or their equivalent, like many programs now, > it's written in at least 4 languages). > 3) I try to exit the program. > 4) While walking it's crazy internal structures, to simply call free(), it > finds an inconsistency and immediately exits. > 5) It forgets to free the shared memory segments since that would be done > after the consistency check. > > If you try to re-run the program now, it may fail due to the shared memory > segments still existing. > > The problem is at no point does the code really care about these internal > consistency checks--except when it wants to exit. And it's deemed not a > real problem since the program does exit (with an error code). > > If the code simply freed the shared memory segments and did exit(0), and > didn't try to balance malloc() and free(), it would just work. We have no way to ensure your diagnosis is correct. The program is clearly buggy, trying to ignore those bugs won't make the bugs disappear, it only hides them. In my world, a hidden bug is much worse than a surfacing bug, as it might reappear at any moment in another place. Based on my experience, I would also say that errors on shutdown are much more likely caused by bugs in joining of threads or bugs in shutting down independent components, NOT by freeing dynamically allocated memory, which is a relatively simple task. Avoiding memory freeing will most likely not fix those bugs, so one still cannot be really sure that all the important cleanup like releasing shared memory is done properly. Technically, if the program is unable or unwilling to join all its threads properly on shutdown, the correct way to terminate is to call _exit(), not exit(). The latter will still try to release static data structures, which may cause havoc with the still running rampant threads.
[toc] | [prev] | [next] | [standalone]
| From | "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> |
|---|---|
| Date | 2021-04-25 01:18 -0700 |
| Message-ID | <s638jo$1quf$1@gioia.aioe.org> |
| In reply to | #79250 |
On 4/25/2021 12:57 AM, Paavo Helde wrote: > 25.04.2021 08:04 Kent Dickey kirjutas: >> In article <s5vd9u$1um1$1@gioia.aioe.org>, >> Chris M. Thomasson <chris.m.thomasson.1@gmail.com> wrote: >>> On 4/23/2021 2:02 PM, jacobnavia wrote: >>>> Le 23/04/2021 à 22:51, Chris M. Thomasson a écrit : >>>>> On 4/23/2021 1:40 PM, jacobnavia wrote: >>>>>> I explained to you why the code doesn't bother to free the >>>>>> memorysince it is used for the whole time that the editor is running. >>>>>> Freeing it just before exiting the program makes no sense. >> >> [ snip] >> >>> I know exactly what you are talking about. However, please clean up >>> after yourself? Pretty please? UNIX is not the only system out there. >>> This is a bad habit to get into. Clean up, gosh darn it. >> >> First: Programs do need to erase any temp files and free any shared >> resources. >> >> I wouldn't have really cared about matching malloc()/free() as an >> issue, but >> I have a problem with a program trying to free() all of its memory when >> qutting that is causing a problem itself. >> >> 1) It allocates shared memory segments. If they already exist, an >> error is >> printed which does not in any way explain the problem. >> 2) It does millions of malloc()'s (or their equivalent, like many >> programs now, >> it's written in at least 4 languages). >> 3) I try to exit the program. >> 4) While walking it's crazy internal structures, to simply call >> free(), it >> finds an inconsistency and immediately exits. >> 5) It forgets to free the shared memory segments since that would be done >> after the consistency check. >> >> If you try to re-run the program now, it may fail due to the shared >> memory >> segments still existing. >> >> The problem is at no point does the code really care about these internal >> consistency checks--except when it wants to exit. And it's deemed not a >> real problem since the program does exit (with an error code). >> >> If the code simply freed the shared memory segments and did exit(0), and >> didn't try to balance malloc() and free(), it would just work. > > We have no way to ensure your diagnosis is correct. The program is > clearly buggy, trying to ignore those bugs won't make the bugs > disappear, it only hides them. In my world, a hidden bug is much worse > than a surfacing bug, as it might reappear at any moment in another place. > > Based on my experience, I would also say that errors on shutdown are > much more likely caused by bugs in joining of threads or bugs in > shutting down independent components, NOT by freeing dynamically > allocated memory, which is a relatively simple task. Avoiding memory > freeing will most likely not fix those bugs, so one still cannot be > really sure that all the important cleanup like releasing shared memory > is done properly. > > Technically, if the program is unable or unwilling to join all its > threads properly on shutdown, the correct way to terminate is to call > _exit(), not exit(). The latter will still try to release static data > structures, which may cause havoc with the still running rampant threads. This is one reason why I always feared detached threads, in a sense... ;^o
[toc] | [prev] | [next] | [standalone]
| From | Paavo Helde <myfirstname@osa.pri.ee> |
|---|---|
| Date | 2021-04-25 11:28 +0300 |
| Message-ID | <s6397m$acb$1@dont-email.me> |
| In reply to | #79251 |
25.04.2021 11:18 Chris M. Thomasson kirjutas: > On 4/25/2021 12:57 AM, Paavo Helde wrote: >> Technically, if the program is unable or unwilling to join all its >> threads properly on shutdown, the correct way to terminate is to call >> _exit(), not exit(). The latter will still try to release static data >> structures, which may cause havoc with the still running rampant threads. > > This is one reason why I always feared detached threads, in a sense... ;^o And rightly so!
[toc] | [prev] | [next] | [standalone]
| From | James Kuyper <jameskuyper@alumni.caltech.edu> |
|---|---|
| Date | 2021-04-25 15:02 -0400 |
| Message-ID | <s64ebb$f71$1@dont-email.me> |
| In reply to | #79251 |
25.04.2021 11:18 Chris M. Thomasson kirjutas: ... > This is one reason why I always feared detached threads, in a sense... ;^o I couldn't help thinking how weird that statement would sound outside of a computer programming context. I imagined someone shying away in terror when someone else used scissors to cut off a piece of thread. :-)
[toc] | [prev] | [next] | [standalone]
| From | "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> |
|---|---|
| Date | 2021-04-26 01:25 -0700 |
| Message-ID | <s65tek$ftr$2@gioia.aioe.org> |
| In reply to | #79257 |
On 4/25/2021 12:02 PM, James Kuyper wrote: > 25.04.2021 11:18 Chris M. Thomasson kirjutas: > ... >> This is one reason why I always feared detached threads, in a sense... ;^o > > I couldn't help thinking how weird that statement would sound outside of > a computer programming context. I imagined someone shying away in terror > when someone else used scissors to cut off a piece of thread. :-) No man, don't cut the cord, join it... ;^) Big time! :^D
[toc] | [prev] | [next] | [standalone]
| From | "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> |
|---|---|
| Date | 2021-04-26 01:26 -0700 |
| Message-ID | <s65tg0$ftr$3@gioia.aioe.org> |
| In reply to | #79257 |
On 4/25/2021 12:02 PM, James Kuyper wrote: > 25.04.2021 11:18 Chris M. Thomasson kirjutas: > ... >> This is one reason why I always feared detached threads, in a sense... ;^o > > I couldn't help thinking how weird that statement would sound outside of > a computer programming context. I imagined someone shying away in terror > when someone else used scissors to cut off a piece of thread. :-) > AHAHAHA!
[toc] | [prev] | [next] | [standalone]
| From | "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> |
|---|---|
| Date | 2021-04-23 14:15 -0700 |
| Message-ID | <s5vdda$s1$1@gioia.aioe.org> |
| In reply to | #79223 |
On 4/23/2021 2:02 PM, jacobnavia wrote: > Le 23/04/2021 à 22:51, Chris M. Thomasson a écrit : >> On 4/23/2021 1:40 PM, jacobnavia wrote: > >>> >>> I explained to you why the code doesn't bother to free the >>> memorysince it is used for the whole time that the editor is running. >>> Freeing it just before exiting the program makes no sense. >>> >> >> Why? Did you create the system its running on? > > The code is for the 10th edition of the UNIX system, and was around > probably since the start of UNIX. > > Within the UNIX system, the OS frees all memory and ressources from a > program that terminates. No, I did not create UNIX, but maybe you should > study it a bit. It is a great system. > > macpro: jacobnavia ~/ man ed > > [snip] > > HISTORY > An ed command appeared in Version 1 AT&T UNIX. Please, don't be one of those people who never use fclose either! https://pubs.opengroup.org/onlinepubs/009695399/functions/fclose.html
[toc] | [prev] | [next] | [standalone]
| From | scott@slp53.sl.home (Scott Lurndal) |
|---|---|
| Date | 2021-04-23 22:25 +0000 |
| Message-ID | <JPHgI.24741$b27.146@fx03.iad> |
| In reply to | #79214 |
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:
>On 4/23/2021 1:29 PM, jacobnavia wrote:
>> Le 23/04/2021 à 21:45, Chris M. Thomasson a écrit :
>>> On 4/23/2021 2:25 AM, jacobnavia wrote:
>>>> Le 23/04/2021 à 09:55, Juha Nieminen a écrit :
>>>>> (I also love how the program has one malloc() and no corresponding
>>>>> free(), because why would it. It's not like it matters by the end
>>>>> of the program...)
>>>>
>>>> If you look a bit longer, maybe you find out why, but maybe not,
>>>> depends on how far you can look.
>>>
>>> for (;;)
>>> {
>>> struct node* = malloc(sizeof(*node));
>>> }
>>>
>>> Hey man, like, don't worry... The GC is there to save us! ;^o
>>
>> The malloc allocates the working area of the editor. It is not freed
>> because it will be always needed; it is realloc'ed when needed, and
>> freed by the OS when the program terminates. This is abvious for anyone
>> reading C.
>>
>
>Oh wow. Don't tell me you are one of those people who think that free()
>should not exist? I have dealt with them before.
He's talking specifically about the ed.c code from Unix V10 that
was recently posted.
The later version (Unixware 2.12) uses sbrk (thus never frees).
[toc] | [prev] | [next] | [standalone]
| From | "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> |
|---|---|
| Date | 2021-04-23 15:31 -0700 |
| Message-ID | <s5vhsn$1pn6$1@gioia.aioe.org> |
| In reply to | #79226 |
On 4/23/2021 3:25 PM, Scott Lurndal wrote:
> "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:
>> On 4/23/2021 1:29 PM, jacobnavia wrote:
>>> Le 23/04/2021 à 21:45, Chris M. Thomasson a écrit :
>>>> On 4/23/2021 2:25 AM, jacobnavia wrote:
>>>>> Le 23/04/2021 à 09:55, Juha Nieminen a écrit :
>>>>>> (I also love how the program has one malloc() and no corresponding
>>>>>> free(), because why would it. It's not like it matters by the end
>>>>>> of the program...)
>>>>>
>>>>> If you look a bit longer, maybe you find out why, but maybe not,
>>>>> depends on how far you can look.
>>>>
>>>> for (;;)
>>>> {
>>>> struct node* = malloc(sizeof(*node));
>>>> }
>>>>
>>>> Hey man, like, don't worry... The GC is there to save us! ;^o
>>>
>>> The malloc allocates the working area of the editor. It is not freed
>>> because it will be always needed; it is realloc'ed when needed, and
>>> freed by the OS when the program terminates. This is abvious for anyone
>>> reading C.
>>>
>>
>> Oh wow. Don't tell me you are one of those people who think that free()
>> should not exist? I have dealt with them before.
>
> He's talking specifically about the ed.c code from Unix V10 that
> was recently posted.
>
> The later version (Unixware 2.12) uses sbrk (thus never frees).
>
Oh, for some reason I thought he was talking about the general case.
Sorry for the misunderstanding. Still, I have created custom allocators
on top on mmap and such. Also, I would always munmap it and close the
mapped file. ;^)
[toc] | [prev] | [next] | [standalone]
| From | "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> |
|---|---|
| Date | 2021-04-23 13:38 -0700 |
| Message-ID | <s5vb7o$u6v$3@gioia.aioe.org> |
| In reply to | #79213 |
On 4/23/2021 1:29 PM, jacobnavia wrote:
> Le 23/04/2021 à 21:45, Chris M. Thomasson a écrit :
>> On 4/23/2021 2:25 AM, jacobnavia wrote:
>>> Le 23/04/2021 à 09:55, Juha Nieminen a écrit :
>>>> (I also love how the program has one malloc() and no corresponding
>>>> free(), because why would it. It's not like it matters by the end
>>>> of the program...)
>>>
>>> If you look a bit longer, maybe you find out why, but maybe not,
>>> depends on how far you can look.
>>
>> for (;;)
>> {
>> struct node* = malloc(sizeof(*node));
>> }
>>
>> Hey man, like, don't worry... The GC is there to save us! ;^o
>
> The malloc allocates the working area of the editor. It is not freed
> because it will be always needed; it is realloc'ed when needed, and
> freed by the OS when the program terminates. This is abvious for anyone
> reading C.
>
Have you ever had to work with non-paged memory before?
[toc] | [prev] | [next] | [standalone]
| From | scott@slp53.sl.home (Scott Lurndal) |
|---|---|
| Date | 2021-04-23 22:27 +0000 |
| Message-ID | <0RHgI.24742$b27.3309@fx03.iad> |
| In reply to | #79217 |
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:
>On 4/23/2021 1:29 PM, jacobnavia wrote:
>> Le 23/04/2021 à 21:45, Chris M. Thomasson a écrit :
>>> On 4/23/2021 2:25 AM, jacobnavia wrote:
>>>> Le 23/04/2021 à 09:55, Juha Nieminen a écrit :
>>>>> (I also love how the program has one malloc() and no corresponding
>>>>> free(), because why would it. It's not like it matters by the end
>>>>> of the program...)
>>>>
>>>> If you look a bit longer, maybe you find out why, but maybe not,
>>>> depends on how far you can look.
>>>
>>> for (;;)
>>> {
>>> struct node* = malloc(sizeof(*node));
>>> }
>>>
>>> Hey man, like, don't worry... The GC is there to save us! ;^o
>>
>> The malloc allocates the working area of the editor. It is not freed
>> because it will be always needed; it is realloc'ed when needed, and
>> freed by the OS when the program terminates. This is abvious for anyone
>> reading C.
>>
>
>Have you ever had to work with non-paged memory before?
Ironically, the program in question was "run on non-paged memory",
i.e. a PDP-11.
[toc] | [prev] | [next] | [standalone]
| From | "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> |
|---|---|
| Date | 2021-04-23 15:34 -0700 |
| Message-ID | <s5vi21$1pn6$2@gioia.aioe.org> |
| In reply to | #79227 |
On 4/23/2021 3:27 PM, Scott Lurndal wrote:
> "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:
>> On 4/23/2021 1:29 PM, jacobnavia wrote:
>>> Le 23/04/2021 à 21:45, Chris M. Thomasson a écrit :
>>>> On 4/23/2021 2:25 AM, jacobnavia wrote:
>>>>> Le 23/04/2021 à 09:55, Juha Nieminen a écrit :
>>>>>> (I also love how the program has one malloc() and no corresponding
>>>>>> free(), because why would it. It's not like it matters by the end
>>>>>> of the program...)
>>>>>
>>>>> If you look a bit longer, maybe you find out why, but maybe not,
>>>>> depends on how far you can look.
>>>>
>>>> for (;;)
>>>> {
>>>> struct node* = malloc(sizeof(*node));
>>>> }
>>>>
>>>> Hey man, like, don't worry... The GC is there to save us! ;^o
>>>
>>> The malloc allocates the working area of the editor. It is not freed
>>> because it will be always needed; it is realloc'ed when needed, and
>>> freed by the OS when the program terminates. This is abvious for anyone
>>> reading C.
>>>
>>
>> Have you ever had to work with non-paged memory before?
>
> Ironically, the program in question was "run on non-paged memory",
> i.e. a PDP-11.
>
The problems I had with non-paged memory was back when I was creating
server software back in WinNT 4.0. Every IOCP operation that's inflight
would use non-paged memory. So, using too much would foobar the system.
[toc] | [prev] | [next] | [standalone]
| From | scott@slp53.sl.home (Scott Lurndal) |
|---|---|
| Date | 2021-04-24 16:33 +0000 |
| Message-ID | <mLXgI.37524$Qf2.15498@fx38.iad> |
| In reply to | #79229 |
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:
>On 4/23/2021 3:27 PM, Scott Lurndal wrote:
>> "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:
>>> On 4/23/2021 1:29 PM, jacobnavia wrote:
>>>> Le 23/04/2021 à 21:45, Chris M. Thomasson a écrit :
>>>>> On 4/23/2021 2:25 AM, jacobnavia wrote:
>>>>>> Le 23/04/2021 à 09:55, Juha Nieminen a écrit :
>>>>>>> (I also love how the program has one malloc() and no corresponding
>>>>>>> free(), because why would it. It's not like it matters by the end
>>>>>>> of the program...)
>>>>>>
>>>>>> If you look a bit longer, maybe you find out why, but maybe not,
>>>>>> depends on how far you can look.
>>>>>
>>>>> for (;;)
>>>>> {
>>>>> struct node* = malloc(sizeof(*node));
>>>>> }
>>>>>
>>>>> Hey man, like, don't worry... The GC is there to save us! ;^o
>>>>
>>>> The malloc allocates the working area of the editor. It is not freed
>>>> because it will be always needed; it is realloc'ed when needed, and
>>>> freed by the OS when the program terminates. This is abvious for anyone
>>>> reading C.
>>>>
>>>
>>> Have you ever had to work with non-paged memory before?
>>
>> Ironically, the program in question was "run on non-paged memory",
>> i.e. a PDP-11.
>>
>
>The problems I had with non-paged memory was back when I was creating
>server software back in WinNT 4.0. Every IOCP operation that's inflight
>would use non-paged memory. So, using too much would foobar the system.
Cutler "borrowed" most of the NT I/O and Memory subsystems from
VMS (the VAX operating system). Which had the same issues with
the non-paged pool.
[toc] | [prev] | [next] | [standalone]
| From | "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> |
|---|---|
| Date | 2021-04-24 22:59 -0700 |
| Message-ID | <s630fu$11vm$1@gioia.aioe.org> |
| In reply to | #79242 |
On 4/24/2021 9:33 AM, Scott Lurndal wrote:
> "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:
>> On 4/23/2021 3:27 PM, Scott Lurndal wrote:
>>> "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:
>>>> On 4/23/2021 1:29 PM, jacobnavia wrote:
>>>>> Le 23/04/2021 à 21:45, Chris M. Thomasson a écrit :
>>>>>> On 4/23/2021 2:25 AM, jacobnavia wrote:
>>>>>>> Le 23/04/2021 à 09:55, Juha Nieminen a écrit :
>>>>>>>> (I also love how the program has one malloc() and no corresponding
>>>>>>>> free(), because why would it. It's not like it matters by the end
>>>>>>>> of the program...)
>>>>>>>
>>>>>>> If you look a bit longer, maybe you find out why, but maybe not,
>>>>>>> depends on how far you can look.
>>>>>>
>>>>>> for (;;)
>>>>>> {
>>>>>> struct node* = malloc(sizeof(*node));
>>>>>> }
>>>>>>
>>>>>> Hey man, like, don't worry... The GC is there to save us! ;^o
>>>>>
>>>>> The malloc allocates the working area of the editor. It is not freed
>>>>> because it will be always needed; it is realloc'ed when needed, and
>>>>> freed by the OS when the program terminates. This is abvious for anyone
>>>>> reading C.
>>>>>
>>>>
>>>> Have you ever had to work with non-paged memory before?
>>>
>>> Ironically, the program in question was "run on non-paged memory",
>>> i.e. a PDP-11.
>>>
>>
>> The problems I had with non-paged memory was back when I was creating
>> server software back in WinNT 4.0. Every IOCP operation that's inflight
>> would use non-paged memory. So, using too much would foobar the system.
>
> Cutler "borrowed" most of the NT I/O and Memory subsystems from
> VMS (the VAX operating system). Which had the same issues with
> the non-paged pool.
>
Yeah. It was scary, in a sense. The problem rose its ugly head when to
many IOCP requests were in flight at the same time. The non-paged pool
could get nuked. I definitely had timeout logic to abort a certain class
of connections during times of stress. If a connection is allowed to
persist with no activity forever, it is still there, using up non-paged
memory. So, I would abort them based on timeouts, kind of a "its been
ten minutes, are you still there?" type of thing. I would cancel all of
the timeout pending connections when the server went into a certian
"panic" mode.
Way back, I even created a version that spawned clients, and forced them
to make a shitload of connections, and transfer huge files back and
forth, like ping pong. For each established connection the server would
store the current number of connections, along with other system data,
into a file. The system was allowed to crash. Reboot, and the file was
read... System crash at this many connections. So, this gave me a bit of
an insight into how many connections the system could handle before it
eats shit.
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2021-04-26 05:22 +0000 |
| Message-ID | <s65imf$53p$1@gioia.aioe.org> |
| In reply to | #79213 |
In comp.lang.c++ jacobnavia <jacob@jacob.remcomp.fr> wrote: > The malloc allocates the working area of the editor. It is not freed > because it will be always needed; it is realloc'ed when needed, and > freed by the OS when the program terminates. This is abvious for anyone > reading C. The main point is that malloc()'ing something and not free()'ing it is bad practice. Not only does it teach you bad habits, it teaches other people reading the code this same bad habit. This is especially egregious in code that's being used for didactic purposes out there, for thousands and thousands of students to see. This potentially (quite potentially) will lead to people learning the bad habit and then not bothering to free() what they malloc() in situations where it actually becomes detrimental. In loops where the amount of leaked memory will start increasing and increasing indefinitely. When the code is complicated enough, and there are hundreds and hundreds of such non-freed mallocs all over the place, in complex code, it becomes a nightmare to fix. On that note, I don't think the term "freed by the OS" should be used in this context. In fact, I would say that anybody who makes that claim doesn't actually understand how malloc() and free() work, and what their relationship is with the OS (at least in most operating systems). It makes it sound like every time you call malloc(), it will make an OS call, which will make the OS allocate a block of memory of that size (which wasn't allocated for the program before), and that the OS itself keeps track of these possibly thousands and thousands, sometimes millions of tiny allocations (think of a linked list, or a binary tree, where each node is allocated individually), and once the program terminates, the OS will "garbage-collect" all these tiny individual allocations and free them again for other programs to use. In other words, as if the OS called free() for you, for each malloc() you did (and didn't explicitly free), when the program ends. More particularly, the claim makes it sound like if the OS didn't "garbage-collect" all the malloc()s you did, which you didn't free() yourself, they would be permanently allocated, never to be reusable by any other program. Of course that's not how it works. In this sense the claim is incorrect.
[toc] | [prev] | [next] | [standalone]
| From | jacobnavia <jacob@jacob.remcomp.fr> |
|---|---|
| Date | 2021-04-26 10:00 +0200 |
| Message-ID | <s65ruu$55i$1@dont-email.me> |
| In reply to | #79264 |
Le 26/04/2021 à 07:22, Juha Nieminen a écrit : > In comp.lang.c++ jacobnavia <jacob@jacob.remcomp.fr> wrote: >> The malloc allocates the working area of the editor. It is not freed >> because it will be always needed; it is realloc'ed when needed, and >> freed by the OS when the program terminates. This is abvious for anyone >> reading C. > > The main point is that malloc()'ing something and not free()'ing it is > bad practice. Not only does it teach you bad habits, it teaches other > people reading the code this same bad habit. This is especially > egregious in code that's being used for didactic purposes out there, > for thousands and thousands of students to see. > 1) The code was presented as a test text for a GREP assignment. The assignment was to rewrite GREP and test it with the ed.c text file. Since you spoke of a simple editor project in C, I showed you one written 50 years ago of just 1700 lines. It compiles and runs 50 years later. Please show me a complex program in C++ from 2000 that compiles unmodified and runs today. 2) In many applications, the information gathered and stored using malloc will be used until the exit of the program: in a compiler, for instance, or in a text editor. A good strategy is to malloc and never free, since all the memory is used until the program exits. This simplifies and accelerates the program. > This potentially (quite potentially) will lead to people learning the > bad habit and then not bothering to free() what they malloc() in > situations where it actually becomes detrimental. Maybe, maybe not. I suppose that people that want to program are able to see when to use malloc and free, when to use just malloc,never freeeing and letting the OS free everything at exit. > In loops where the > amount of leaked memory will start increasing and increasing indefinitely. > When the code is complicated enough, and there are hundreds and hundreds > of such non-freed mallocs all over the place, in complex code, it becomes > a nightmare to fix. > This has a simple fix (that I have used a lot): 1) Replace all malloc calls by calls to Mymalloc 2) Write a simple function Mymalloc that allocates from a heap 3) Free the heap when the program terminates. This way, a program that never freed anything can be included into a larger project that needs the free(). > On that note, I don't think the term "freed by the OS" should be used > in this context. In fact, I would say that anybody who makes that claim > doesn't actually understand how malloc() and free() work, and what their > relationship is with the OS (at least in most operating systems). > I think that you are the one that doesn't understand. Let's see: > It makes it sound like every time you call malloc(), it will make an OS > call, which will make the OS allocate a block of memory of that size > (which wasn't allocated for the program before), This is exactly what happens. The OS allocates a block of memory that malloc/free manages. All mallocs use some API for calling the OS. and that the OS itself > keeps track of these possibly thousands and thousands, sometimes millions > of tiny allocations (think of a linked list, or a binary tree, where each > node is allocated individually), and once the program terminates, the OS > will "garbage-collect" all these tiny individual allocations and free > them again for other programs to use. In other words, as if the OS called > free() for you, for each malloc() you did (and didn't explicitly free), > when the program ends. The OS frees the heap of the application (conceptually). > > More particularly, the claim makes it sound like if the OS didn't > "garbage-collect" all the malloc()s you did, which you didn't free() > yourself, they would be permanently allocated, never to be reusable by > any other program. > ???? > Of course that's not how it works. In this sense the claim is incorrect. >
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2021-04-26 09:57 +0000 |
| Message-ID | <s662qr$1f6i$1@gioia.aioe.org> |
| In reply to | #79268 |
In comp.lang.c++ jacobnavia <jacob@jacob.remcomp.fr> wrote: > Since you spoke of a simple editor project in C, I showed you one > written 50 years ago of just 1700 lines. Not comparable because my entire point was about how laborious and error-prone it is to handle *dynamically allocated* (and length-changing) strings. The program you posted uses a static array for the lines, with a fixed maximum length. Not really comparable. > It compiles and runs 50 years > later. Please show me a complex program in C++ from 2000 that compiles > unmodified and runs today. Can you show me a C++ program from 2000 that doesn't? > 2) In many applications, the information gathered and stored using > malloc will be used until the exit of the program: in a compiler, for > instance, or in a text editor. A good strategy is to malloc and never > free, since all the memory is used until the program exits. This > simplifies and accelerates the program. For starters, allocating some kind of memory buffer that gets reused in the program for many things doesn't stop you from freeing it at the end. Secondly, that's not really an option for a text editor where you have to load a text file into RAM and allow the user to edit its lines (by eg. adding content to them). You can't do this with one single allocation. (You can read the file into RAM with one single allocation, but you can't then support adding stuff to it without reallocation. Moreover, if it's a text editor you probably want to allocate each line individually to allow them to be grown efficiently, without having to realloc the entire thing.) >> In loops where the >> amount of leaked memory will start increasing and increasing indefinitely. >> When the code is complicated enough, and there are hundreds and hundreds >> of such non-freed mallocs all over the place, in complex code, it becomes >> a nightmare to fix. >> > > This has a simple fix (that I have used a lot): > 1) Replace all malloc calls by calls to Mymalloc > 2) Write a simple function Mymalloc that allocates from a heap > 3) Free the heap when the program terminates. This way, a program that > never freed anything can be included into a larger project that needs > the free(). That doesn't make any difference. If you are leaking memory in a loop, your program will start consuming more and more RAM until it runs out of it. It makes no difference whether you use your own allocator for this or not, if you never free the memory blocks that you don't need anymore. >> It makes it sound like every time you call malloc(), it will make an OS >> call, which will make the OS allocate a block of memory of that size >> (which wasn't allocated for the program before), > > This is exactly what happens. The OS allocates a block of memory that > malloc/free manages. All mallocs use some API for calling the OS. No, it's not. malloc() and free() are (typically) handled by the C runtime library. This library will make a system call to ask for more heap space only if needed. If a malloc() can be done within the current heap, it won't ask the OS for more. The only thing that the OS sees is the heap expansion requests (and possibly heap shrinking requests). It doesn't see the individual mallocs and frees. It doesn't know nor care which parts of the heap are "unused" and which are "in use" by the program internally. > and that the OS itself >> keeps track of these possibly thousands and thousands, sometimes millions >> of tiny allocations (think of a linked list, or a binary tree, where each >> node is allocated individually), and once the program terminates, the OS >> will "garbage-collect" all these tiny individual allocations and free >> them again for other programs to use. In other words, as if the OS called >> free() for you, for each malloc() you did (and didn't explicitly free), >> when the program ends. > > The OS frees the heap of the application (conceptually). That's what I said. It doesn't care about any "mallocs" or "frees" of the program. It just sees a heap, and doesn't care what the program does with it. When the program ends, the OS reclaims that heap.
[toc] | [prev] | [next] | [standalone]
| From | Robert Latest <boblatest@yahoo.com> |
|---|---|
| Date | 2021-04-26 10:41 +0000 |
| Message-ID | <ienjmeFl5j5U2@mid.individual.net> |
| In reply to | #79283 |
["Followup-To:" header set to comp.lang.c.] Juha Nieminen wrote: > Not comparable because my entire point was about how laborious and > error-prone it is to handle *dynamically allocated* (and length-changing) > strings. All coding is laborious and error prone if you're both lazy and sloppy. -- robert
[toc] | [prev] | [next] | [standalone]
| From | jacobnavia <jacob@jacob.remcomp.fr> |
|---|---|
| Date | 2021-04-26 13:20 +0200 |
| Message-ID | <s667mf$5uc$1@dont-email.me> |
| In reply to | #79283 |
Le 26/04/2021 à 11:57, Juha Nieminen a écrit :
> Can you show me a C++ program from 2000 that doesn't?
Breaking changes in C++ 2011
1) the introduction of explicit operator bool() in the standard library,
replacing old instances of operator void*().
2) #define u8 "abc"
const char *s = u8"def"; // Previously "abcdef", now "def"
3) #define _x "there"
"hello"_x // now a user-defined-string-literal. Previously, expanded _x
4) New keywords: alignas, alignof, char16_t, char32_t, constexpr,
decltype, noexcept, nullptr, static_assert, and thread_local
5) Certain integer literals larger than can be represented by long could
change from an unsigned integer type to signed long long.
6) Valid C++ 2003 code that uses integer division rounds the result
toward 0 or toward negative infinity, whereas C++0x always rounds the
result toward 0.
7) struct A { private: A(); };
struct B : A { };
int main() { sizeof B(); /* valid in C++03, invalid in C++0x */ }
Such sizeof tricks have been used by some SFINAE, and needs to be
changed now :)
8) banning of narrowing conversions during aggregate initialization:
int a = {1.0; }; // error
9) Implicit move breaks C++ 2003 code. The long explanation why is to be
found at:
http://web.archive.org/web/20140110035813/http://cpp-next.com/archive/2010/10/implicit-move-must-go/
10) I remember that in an older version of C++ the templates arguments
are checked and must be defined at the point of expansion, the new
version of the language needs that they are defined at the point of
definition. Or something like that. I earned two weeks consulting to
update a huge codebase. Actually I love C++ :-)
And I will stop here... You apparently have no idea how c++ has changed
over the years, with each new version incompatible in some point with
the older one.
Only in C you can still use the code of 50 years ago.
[toc] | [prev] | [next] | [standalone]
Page 3 of 5 — ← Prev page 1 2 [3] 4 5 Next page →
Back to top | Article view | comp.lang.c++
csiph-web