Re: Is this good style of C++?
From: Ioannis Vranos (ivr_at_remove.this.grad.com)
Date: 12/06/04
- Next message: Jack Klein: "Re: Why .NET is faster than Java"
- Previous message: Steve Sobol: "Re: [OT] Using hobby source code in your job ?"
- In reply to: Ioannis Vranos: "Re: Is this good style of C++?"
- Next in thread: Morgan Cheng: "Re: Is this good style of C++?"
- Reply: Morgan Cheng: "Re: Is this good style of C++?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Jack Klein: "Re: Why .NET is faster than Java"
- Previous message: Steve Sobol: "Re: [OT] Using hobby source code in your job ?"
- In reply to: Ioannis Vranos: "Re: Is this good style of C++?"
- Next in thread: Morgan Cheng: "Re: Is this good style of C++?"
- Reply: Morgan Cheng: "Re: Is this good style of C++?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|