|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hello everyone,
Through my testing and study of RAII (Resource Acquisition Is Initialization) pattern, I think it can solve resource release issue in the following two situations, 1. Local function object (on stack); 2. Object (either on heap or stack) pointer by auto_ptr; But it has the limitation that the object pointed by a normal pointer and allocated on heap (using new or new[]) can not be automatically released, either the function returns normally or during exception stack unwinding. Is that correct? thanks in advance, George |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
George2 wrote:
> Hello everyone, > > > Through my testing and study of RAII (Resource Acquisition Is > Initialization) pattern, I think it can solve resource release issue > in the following two situations, > > 1. Local function object (on stack); > 2. Object (either on heap or stack) pointer by auto_ptr; > The name of this idiom literally suggests such usage, and of course the "limitation" > But it has the limitation that the object pointed by a normal pointer > and allocated on heap (using new or new[]) can not be automatically > released, do you mean GC? either the function returns normally or during exception > stack unwinding. Is that correct? if you returning an auto_ptr, there's no such issue, as copy constructor of auto_ptr guarantees no throw. anyway, I still not quite understand what you mean. |
|
![]() |
| Outils de la discussion | |
|
|