Topic: [Fwd: Q about auto_ptr]
Author: Xavier Huet <xavier.huet@sophia.siemens-scg.com>
Date: 1998/05/16 Raw View
[Moderator's note: also posted to comp.lang.c++.moderated, apparently.]
Snyder brian scott wrote:
> Hello. I'm curious as I've been going through reading/learning about
> exception handling in C++, I've started using the auto_ptr template
> class, and
> it seems to me, that even if you don't need to use it for 'resource
> aquisation' type model, it is still very usefull to gaurantee no memory
> leaks,
> so is there ever a situation where you wouldn't want to use it, or
> should I
> say, is there ever a situation where you don't want to use it, over a
> regular
> pointer to an object?
>
> Thanx,
> brian
I want to add more questions to brian's ones.
I was using the auto_ptr implementation from RogueWave
and what I found is strange. the ownership is set with the
pointer value.
When you pass ownership from one source auto_pr to a
target auto_ptr, the source auto_ptr is set to 0.
So it means that we can never have 2 auto_ptrs of the same pointer.
ex :int* pi = new int(2)
auto_ptr<int> owner1 = p; <---- owner1 is owner and holds p
auto_ptr<int> owner2 = owner1; <--- owner2 is owner, holds p
but
owner1
now is no more owner
and holds NULL.
I read the CD2 but I didn't find something explicit about this kind of
behaaviour.
auto_ptr is a single owner solution. but nothing say that it must be a
single holder
solution too.
Could you give informations about this.
~Xavier
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Alexandre Oliva <oliva@dcc.unicamp.br>
Date: 1998/05/17 Raw View
Xavier Huet <xavier.huet@sophia.siemens-scg.com> writes:
> I was using the auto_ptr implementation from RogueWave
> When you pass ownership from one source auto_pr to a
> target auto_ptr, the source auto_ptr is set to 0.
That's correct, it's required in the FDIS. The auto_ptr specification
has been modified since the CD2.
--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]