Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #13009

Re: C++ Memory Management Question

From "Paul" <pchrist<nospam>or@yahoo.co.uk>
Newsgroups comp.lang.c++
Subject Re: C++ Memory Management Question
Date 2012-01-02 23:27 +0000
Organization Netfront http://www.netfront.net/
Message-ID <jdtegu$3bd$1@adenine.netfront.net> (permalink)
References (10 earlier) <166dnXvy0p2XXZzSnZ2dnUVZ8sadnZ2d@giganews.com> <jdsjvs$2em2$1@adenine.netfront.net> <e8Kdnfm9b7RMR5zSnZ2dnUVZ7vOdnZ2d@giganews.com> <jdtaqm$13m$1@adenine.netfront.net> <roSdnVh1J5d6qJ_SnZ2dnUVZ7vednZ2d@giganews.com>

Show all headers | View raw


"Leigh Johnston" <leigh@i42.co.uk> wrote in message 
news:roSdnVh1J5d6qJ_SnZ2dnUVZ7vednZ2d@giganews.com...
> On 02/01/2012 22:24, Paul <pchrist wrote:
>> "Leigh Johnston"<leigh@i42.co.uk>  wrote in message
>> news:e8Kdnfm9b7RMR5zSnZ2dnUVZ7vOdnZ2d@giganews.com...
>>> On 02/01/2012 15:54, Paul<pchrist wrote:
>>>> "Leigh Johnston"<leigh@i42.co.uk>   wrote in message
>>>> news:166dnXvy0p2XXZzSnZ2dnUVZ8sadnZ2d@giganews.com...
>>> [snip]
>>>>
>>>>> 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.
>>>>>
>>>> Why is it absurd to check each allocation for a failure?
>>>
>>> If you knew how to properly use C++ exception handling you would not be
>>> asking that question.  You need to learn about RAII and such; I 
>>> recommend
>>> you read a decent C++ book which should cover this (and it is not the
>>> first time I have made this recommendation to you).
>>>
>> Allowing the program to terminate is not what I would call properly using
>> C++ EH.
>> What is the point in RAII freeing up memory, with stack created object
>> destructors, if the program is going to terminate anyway?
>> Apparently you dont use C++ EH because you simply allow the program to
>> terminate and catch no exceptions, so how does this make you such an 
>> expert
>> on the subject?
>
> So you have just spent half an hour reading up on RAII from the Web and of 
> course you now think you are expert enough to make that comment?  Please.
>
> RAII clean up kicks in when any exception is thrown not just 
> std::bad_alloc exceptions.

RAII just gurantees that stack contructed objects will have thier 
destructors called.


>
> I typically have a top-level try/catch in main() (which ensures RAII clean 
> up happens for any exceptions I don't catch elsewhere) which displays a 
> nice error message and then re-throws from that to cause process 
> termination.

There is no point in RAII if you are simply going to terminate the process 
anyway, the OS will reclaim the resources on termination anyway.


>
> The type of program I am writing will dictate whether or not a 
> std::bad_alloc exception raised during a particular type of object 
> construction is recoverable or should result in program termination. 
> Typically the software I write is layered in such a way that any try/catch 
> is several layers removed from the function raising the exception; this is 
> key to understanding why you don't want to explicitly check all possible 
> memory allocation requests for failure in C++; C++ exception handling 
> exists because it replaces the old fashioned checking of error codes of 
> functions which sucks.

So according to you there is your typical way of doing things and what you 
describe as the old fashioned checking of error codes. No other style of 
programming is worth considering as far as you are concerned, only these two 
ways.

>
> If you followed my advice months ago and read a decent C++ book you 
> probably would not be still posting this usual dross of yours; accusing 
> others of the ignorance which you yourself possess (a case of 
> psychological projection).
>

I've known about C++ EH and RAII for many years , granted I am not recently 
familiar with this as I would be if I used it everyday, but I don't consider 
you to be an expert on this subject and I certainly don't think you are in a 
position to give me advice on it.



--- Posted via news://freenews.netfront.net/ - Complaints to news@netfront.net ---

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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