Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #13017
| From | 88888 Dihedral <dihedral88888@googlemail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: C++ Memory Management Question |
| Date | 2012-01-02 21:45 -0800 |
| Organization | http://groups.google.com |
| Message-ID | <9114090.107.1325569550443.JavaMail.geo-discussion-forums@prdv33> (permalink) |
| References | (6 earlier) <wuqdnZzxuYoWM53SnZ2dnUVZ8iCdnZ2d@giganews.com> <jdqck8$cua$1@adenine.netfront.net> <EaOdnR_ieaQwJZ3SnZ2dnUVZ8nCdnZ2d@giganews.com> <jds499$1rrk$1@adenine.netfront.net> <166dnXvy0p2XXZzSnZ2dnUVZ8sadnZ2d@giganews.com> |
Leigh Johnston於 2012年1月2日星期一UTC+8下午10時32分44秒寫道: > On 02/01/2012 11:26, Paul > "Leigh Johnston"<le...@i42.co.uk> wrote in message > > news:EaOdnR_ieaQwJZ3SnZ2dnUVZ8nCdnZ2d@giganews.com... > >> On 01/01/2012 19:36, Paul > >> "Leigh Johnston"<le...@i42.co.uk> wrote in message > >>> news:wuqdnZzxuYoWM53SnZ2dnUVZ8iCdnZ2d@giganews.com... > >>>> On 01/01/2012 14:39, Victor Bazarov wrote: > >>>>> On 1/1/2012 2:25 AM, Goran wrote: > >>>>>> On Dec 31 2011, 7:04 pm, Victor Bazarov<v.baza...@comcast.invalid> > >>>>>> wrote: > >>>>>>> Neither a word processor nor a video editor should even attempt > >>>>>>> loading > >>>>>>> anything if it determines that the attempt might cause it to run out > >>>>>>> of > >>>>>>> memory. If they can't determine that before opening the file, they > >>>>>>> aren't worth our time to discuss them. > >>>>>> > >>>>>> I disagree. There's no guarantee whatsoever that any allocation will > >>>>>> succeed, so theoretically, your idea is unsound. Practically, it's > >>>>>> difficult to implement more often than not. I was doing it, and > >>>>>> looking back, it was an error. E.g. it's easy only if you merely load > >>>>>> file contents into memory. I don't believe that happens all that > >>>>>> often. > >>>>>> > >>>>>> What you're saying is equivalent to going to supermarket to see > >>>>>> whether it has mayonnaise, then going back for money, then coming back > >>>>>> to buy. > >>>>> > >>>>> Not at all. There is always some reasonable portion that, when > >>>>> allocated > >>>>> fresh, is likely to be granted to the process. And if allocating that > >>>>> reasonable portion fails, quit and tell the user he can't use that > >>>>> system for that operation without any changes (e.g. making some more > >>>>> resources available by either adding spare ones or releasing the ones > >>>>> currently used). I am saying that if you come to the store to buy > >>>>> mayonnaise, there is (a) no sense to reach into your pocket if the mayo > >>>>> is not on the shelf (file is missing), (b) no need to buy the > >>>>> lifetime's > >>>>> worth in advance (even if you know what your lifetime is going to be). > >>>>> We buy mayo in portions, consume, then come to buy some more. Besides, > >>>>> we have replenishment of money, so it's a bad analogy anyway. > >>>>> > >>>>> In 1960s programmers wrote solving large systems of linear equations > >>>>> (hundreds and even thousands) on a system that only had 100 cells of > >>>>> memory. How did they manage? What is so different about it when it's > >>>>> not > >>>>> 100 but 100 billion cells? There will be problems that aren't going to > >>>>> fit in memory whole. Another example: on MS-DOS there was a text editor > >>>>> called MultiEdit that managed to deal with files much larger than the > >>>>> available 640KB. How did they do it? > >>>>> > >>>>> What I am saying is that there is always a way to deal with large > >>>>> amounts of data without having to load it all in memory. > >>>> > >>>> I agree with Goran; you are talking rubbish; there is no standard way to > >>>> determine if an allocation *attempt* will succeed or not; to avoid OOM > >>>> either pre-allocate whatever you need up front if memory requirements > >>>> are > >>>> bounded otherwise you must handle allocation *failures*. > >>>> > >>> The problem with this discussion is that its very OS speific. > >>> > >>> To create a robust memory managment system would require good knowledge > >>> of > >>> the underlying OS and an understanding of all possible allocation > >>> failures. > >>> > >>> I think it is possible that an OS may provide methods for checking > >>> available > >>> memory. > >>> > >>> I do agree with Carlo that profession programmes should exit gracefully , > >>> if > >>> possible. True it may not always be possible as there may be times when a > >>> complete system crash is inevitable , but a program should at least *try* > >>> to > >>> save work or recover under low memory conditions. > >> > >> That is fine if "save work" or "recover" do not allocate memory otherwise > >> they may also suffer a memory allocation failure. Aborting the program > >> (what you call "crashing") on allocation failure is perfectly acceptable > >> for a subset of all possible programs and this is what will happen if you > >> don't handle (catch) allocation failure exceptions such as std::bad_alloc. > >> > > > > This is not what I meant by crashing, I said a system crash , that is the OS > > encountering a unrecoverable and critical error. You are speaking about > > aborting a program , a program just dying whenever it encounters an > > exception.. > > This thread is not about unrecoverable or critical OS errors; it is > about memory allocation failures. > > Even if an OS provided a mechanism to determine available memory what > guarantee would there be that the amount of available memory reported by > such a function would be the same as the amount of available memory when > the allocation request is actually made? > > Are you suggesting that one should check available memory before calling > any function that may allocate memory? This is of course absurd. > > Are you suggesting that in C++ one should only use the no-throw version > of 'new' and check every allocation request at the site of the request > and report an error and "save work" or "recover"? This is of course absurd. > > HTH. > > /Leigh What are you talking about? If you just play with programs that need small amount of memory from the OS, then a lot error checking operations can be omitted. But those are low paid programmers' jobs definitely. Please don't baby sister too much for those ambitious talented young to have the bad habits to avoid exploring and experimenting for further professional tricks.
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
C++ Memory Management Question Datesfat Chicks <datesfat.chicks@gmail.com> - 2011-12-31 08:56 -0500
Re: C++ Memory Management Question Victor Bazarov <v.bazarov@comcast.invalid> - 2011-12-31 09:44 -0500
Re: C++ Memory Management Question Datesfat Chicks <datesfat.chicks@gmail.com> - 2011-12-31 10:17 -0500
Re: C++ Memory Management Question "MikeWhy" <boat042-nospam@yahoo.com> - 2011-12-31 12:56 -0600
Re: C++ Memory Management Question jt@toerring.de (Jens Thoms Toerring) - 2011-12-31 19:05 +0000
Re: C++ Memory Management Question Carlo Milanesi <carlo.nospam.milanesi@libero.it> - 2011-12-31 18:18 +0100
Re: C++ Memory Management Question Victor Bazarov <v.bazarov@comcast.invalid> - 2011-12-31 13:04 -0500
Re: C++ Memory Management Question Carlo Milanesi <carlo.nospam.milanesi@libero.it> - 2011-12-31 19:42 +0100
Re: C++ Memory Management Question Goran <goran.pusic@gmail.com> - 2011-12-31 23:25 -0800
Re: C++ Memory Management Question Victor Bazarov <v.bazarov@comcast.invalid> - 2012-01-01 09:39 -0500
Re: C++ Memory Management Question Goran <goran.pusic@gmail.com> - 2012-01-01 08:20 -0800
Re: C++ Memory Management Question Leigh Johnston <leigh@i42.co.uk> - 2012-01-01 19:05 +0000
Re: C++ Memory Management Question "Paul" <pchrist<nospam>or@yahoo.co.uk> - 2012-01-01 19:36 +0000
Re: C++ Memory Management Question Leigh Johnston <leigh@i42.co.uk> - 2012-01-01 19:49 +0000
Re: C++ Memory Management Question "Paul" <pchrist<nospam>or@yahoo.co.uk> - 2012-01-02 11:26 +0000
Re: C++ Memory Management Question Leigh Johnston <leigh@i42.co.uk> - 2012-01-02 14:32 +0000
Re: C++ Memory Management Question "Paul" <pchrist<nospam>or@yahoo.co.uk> - 2012-01-02 15:54 +0000
Re: C++ Memory Management Question Leigh Johnston <leigh@i42.co.uk> - 2012-01-02 16:26 +0000
Re: C++ Memory Management Question "Paul" <pchrist<nospam>or@yahoo.co.uk> - 2012-01-02 16:58 +0000
Re: C++ Memory Management Question Leigh Johnston <leigh@i42.co.uk> - 2012-01-02 21:14 +0000
Re: C++ Memory Management Question Ian Collins <ian-news@hotmail.com> - 2012-01-03 11:11 +1300
Re: C++ Memory Management Question scott@slp53.sl.home (Scott Lurndal) - 2012-01-03 20:53 +0000
Re: C++ Memory Management Question Leigh Johnston <leigh@i42.co.uk> - 2012-01-03 21:21 +0000
Re: C++ Memory Management Question Ian Collins <ian-news@hotmail.com> - 2012-01-04 12:15 +1300
Re: C++ Memory Management Question gwowen <gwowen@gmail.com> - 2012-01-04 08:20 -0800
Re: C++ Memory Management Question "Paul" <pchrist<nospam>or@yahoo.co.uk> - 2012-01-02 22:24 +0000
Re: C++ Memory Management Question Leigh Johnston <leigh@i42.co.uk> - 2012-01-02 22:55 +0000
Re: C++ Memory Management Question "Paul" <pchrist<nospam>or@yahoo.co.uk> - 2012-01-02 23:27 +0000
Re: C++ Memory Management Question Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-01-10 01:01 -0800
Re: C++ Memory Management Question 88888 Dihedral <dihedral88888@googlemail.com> - 2012-01-02 21:45 -0800
Re: C++ Memory Management Question Goran <goran.pusic@gmail.com> - 2012-01-03 00:32 -0800
Re: C++ Memory Management Question "Paul" <pchrist<nospam>or@yahoo.co.uk> - 2012-01-03 17:34 +0000
Re: C++ Memory Management Question Nick Keighley <nick_keighley_nospam@hotmail.com> - 2012-01-10 00:47 -0800
Re: C++ Memory Management Question BCFD36 <bcfd36@cruzio.com> - 2012-01-10 22:57 -0800
Re: C++ Memory Management Question Ian Collins <ian-news@hotmail.com> - 2012-01-03 09:31 +1300
Re: C++ Memory Management Question Leigh Johnston <leigh@i42.co.uk> - 2012-01-02 21:02 +0000
Re: C++ Memory Management Question Ian Collins <ian-news@hotmail.com> - 2012-01-03 11:09 +1300
Re: C++ Memory Management Question Leigh Johnston <leigh@i42.co.uk> - 2012-01-01 18:57 +0000
Re: C++ Memory Management Question jgk@panix.com (Joe keane) - 2012-01-01 22:04 +0000
Re: C++ Memory Management Question Carlo Milanesi <carlo.nospam.milanesi@libero.it> - 2012-01-02 00:37 +0100
Re: C++ Memory Management Question yatremblay@bel1lin202.(none) (Yannick Tremblay) - 2012-01-09 17:41 +0000
Re: C++ Memory Management Question Carlo Milanesi <carlo.milanesi@libero.it> - 2012-01-13 08:14 -0800
Re: C++ Memory Management Question Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-01-01 18:05 +0000
Re: C++ Memory Management Question Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-12-31 07:25 -0800
Re: C++ Memory Management Question Torsten Mueller <dev-null@shared-files.de> - 2011-12-31 16:41 +0100
Re: C++ Memory Management Question Nobody <nobody@nowhere.com> - 2012-01-01 09:16 +0000
Re: C++ Memory Management Question Datesfat Chicks <datesfat.chicks@gmail.com> - 2012-01-02 16:48 -0500
Re: C++ Memory Management Question Goran <goran.pusic@gmail.com> - 2012-01-03 00:02 -0800
Re: C++ Memory Management Question Datesfat Chicks <datesfat.chicks@gmail.com> - 2012-01-03 12:53 -0500
Re: C++ Memory Management Question Nobody <nobody@nowhere.com> - 2012-01-03 19:46 +0000
Re: C++ Memory Management Question Goran <goran.pusic@gmail.com> - 2012-01-04 00:11 -0800
Re: C++ Memory Management Question Nobody <nobody@nowhere.com> - 2012-01-04 09:30 +0000
Re: C++ Memory Management Question Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-01-04 19:28 +0000
Re: C++ Memory Management Question Nobody <nobody@nowhere.com> - 2012-01-04 22:09 +0000
Re: C++ Memory Management Question Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-01-05 11:43 +0000
Re: C++ Memory Management Question Christian Gollwitzer <auriocus@gmx.de> - 2012-01-01 18:13 +0100
Re: C++ Memory Management Question "io_x" <a@b.c.invalid> - 2012-01-01 20:11 +0100
Re: C++ Memory Management Question Datesfat Chicks <datesfat.chicks@gmail.com> - 2012-01-02 16:51 -0500
Re: C++ Memory Management Question Simon Quinn <sq@nospam.com> - 2012-01-05 07:54 +0000
Re: C++ Memory Management Question darylew@gmail.com - 2012-01-10 10:19 -0800
csiph-web