Re: Is this good style of C++?

From: Ioannis Vranos (ivr_at_remove.this.grad.com)
Date: 12/06/04


Date: Mon, 06 Dec 2004 04:51:05 +0200

Ioannis Vranos wrote:
>
> Morgan Cheng wrote:
>
>> If I implements RAII strictly, do you mean that memory leak can be
>> avoided totally? even exception is possibly to be thrown?
>
>
>
> Yes, along with other resource types leaks (IP connections, file
> operations etc).
>
>
> All C++ standard library types support RAII (except of the C subset
> types of course).
>
>
>
>> So, RAII is based on the fact that: At the end of a scope, through
>> normal running or exception thrown, objects in the scope will be
>> destructed.
>
>
>
> Exactly.
>
>
>
>> If resource is allocated explictly, objects pointed by pointer will
>> not be released by releasing the pointer. So, we wrap dynamic resource
>> allocation with a local object.
>> Am my understanding right?
>
>
>
> Yes.

I want to mention here that using RAII in your applications is fairly easy.

The most obvious way is to use a vector for your objects (or some other
standard library container if it is more suitable), instead of an array
in the free store.

And you have no space/time cost doing this.

-- 
Ioannis Vranos
http://www23.brinkster.com/noicys


Relevant Pages

  • Re: Exception handling help please
    ... >> void MyFunc() ... > exception object in the throw expression, ... >> still does stuff after the catch block, then isn't there a memory leak ... then at least the caller could delete the pointer. ...
    (comp.lang.cpp)
  • Re: new revision ada
    ... The hidden string should contain a pointer to the data to pass, ... a memory leak could happen is if you don't properly handle the exception, ... in which case a memory leak is probably the least of your problems. ...
    (comp.lang.ada)
  • hunting down a memory leak
    ... the two most likely causes are either a memory leak in the ... ..NET exception classes. ... using (SqlConnection oConn = new SqlConnection(sConnection)) ... SqlCommand oCommand = oXMLCommand.CreateSqlCommand; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: many exceptions cause memory leak?
    ... This function allocates an Exception Occurrence from the heap and copies the data from Source into this new occurrence. ... Failure to deallocate the results of the Save_Occurrence function would certainly result in a memory leak. ... Final Water Mark: ...
    (comp.lang.ada)
  • Re: Web service doesnt run
    ... "Ioannis Vranos" wrote in message ... >> your IIS. ... > Server Error in '/Converter' Application. ... An unhandled exception occurred during the execution of the ...
    (microsoft.public.dotnet.distributed_apps)