Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #160277 > 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 78 — 23 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 steveh <steveh@nospam.invalid> - 2021-04-22 19:31 +0000
Re: Text editor project in C Bonita Montero <Bonita.Montero@gmail.com> - 2021-04-23 19:25 +0200
Re: Text editor project in C Oğuz <oguzismailuysal@gmail.com> - 2021-04-23 12:21 -0700
Re: Text editor project in C Bonita Montero <Bonita.Montero@gmail.com> - 2021-04-24 05:10 +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 silas poulson <Silas8642@hotmail.co.uk> - 2021-04-23 07:32 -0700
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 scott@slp53.sl.home (Scott Lurndal) - 2021-04-23 20:25 +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 Bonita Montero <Bonita.Montero@gmail.com> - 2021-04-26 18:04 +0200
Page 2 of 4 — ← Prev page 1 [2] 3 4 Next page →
| From | "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> |
|---|---|
| Date | 2021-04-23 17:43 -0700 |
| Message-ID | <s5vpiq$f6m$1@gioia.aioe.org> |
| In reply to | #160316 |
On 4/23/2021 5:20 PM, Bart wrote: > On 23/04/2021 22:13, Chris M. Thomasson 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. >>>>> >>>> >>>> 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. >> >> 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. > > Which OSes don't free the resources of an application that's just > terminated? I cannot remember if named win3d mutex/semaphore/event/ect are automatically cleaned up... I think there could be an issue with SYSV shared memory. Iirc, some device drivers. I need to do more research. However, cleaning up after yourself is a good habit to get into. Afaict, the OS cleans up to help prevent badly written code from bringing the system down? A nit pick, but I can also think of leaking disk space wrt a program creating a temporary file with a random name or something, then forgetting to delete it. The OS is not going to automatically delete the file. Forgetting to unlock a robust mutex can be interesting, think of locking it as acquiring a resource, and unlocking as releasing it. It can cause a robust mutex to go into an abandoned state. Try to avoid that as much as possible. WAIT_ABANDONED or EOWNERDEAD should be minimized. > > What happens if the app crashes before it manages to free them? > > What about resources such as screen window handles, bitmaps, dynamic > libraries,.... ? > > How about the memory that that the process itself takes up for its own > code, or its stack; how is an application supposed to free that? > > > Isn't this exacly what an OS is supposed to do? Depends on the system your are using. Well, its better to clean up after yourself.
[toc] | [prev] | [next] | [standalone]
| From | kegs@provalid.com (Kent Dickey) |
|---|---|
| Date | 2021-04-25 00:04 -0500 |
| Message-ID | <baWdnYboN_HlZRn9nZ2dnUU7-anNnZ2d@giganews.com> |
| In reply to | #160307 |
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. Kent
[toc] | [prev] | [next] | [standalone]
| From | "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> |
|---|---|
| Date | 2021-04-24 22:29 -0700 |
| Message-ID | <s62uok$gva$1@gioia.aioe.org> |
| In reply to | #160332 |
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. Actually, I am quite fond of region allocators, where there is no need to balance between allocating and flushing a region. I wrote one a while back: https://groups.google.com/g/comp.lang.c/c/7oaJFWKVCTw/m/sSWYU9BUS_QJ https://pastebin.com/raw/f37a23918 I used it in various ways, even partitioning it to allow for "partial" region resets. This is using a nasty hack, to get alignment. But, shit happens. ;^o Layering a malloc/free on top of a region allocator can sometimes allow for the free function to be a no-op. > 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. Still, if you are running any type of "event" loop, memory leaks can be a problem. I had to debug a horrible one where a subtle race-condition caused memory leaks over time. The horrible nature of it was the race condition would only trip at basically random times. Speaking of random, for fun, check out the random number generator thing I wrote that is based on race conditions: https://groups.google.com/g/comp.lang.c++/c/7u_rLgQe86k/m/XiqELOEECAAJ lol. ;^)
[toc] | [prev] | [next] | [standalone]
| 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 | #160332 |
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 | #160332 |
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 | #160336 |
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 | #160337 |
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 | #160337 |
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 | #160339 |
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 | #160339 |
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 | #160306 |
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 | #160298 |
"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 | #160309 |
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 | #160297 |
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 | #160301 |
"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 | #160310 |
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 | #160312 |
"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 | #160321 |
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 | #160297 |
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 | #160340 |
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]
Page 2 of 4 — ← Prev page 1 [2] 3 4 Next page →
Back to top | Article view | comp.lang.c
csiph-web