Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: ANN: AutoNe...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 12 of 13 Topic 9589 of 10096
Post > Topic >>

Re: ANN: AutoNewPtr (oh yes, yet another smartpointer)

by rpbg123@[EMAIL PROTECTED] (Roland Pibinger) May 16, 2008 at 05:29 PM

On Wed, 14 May 2008 15:11:54 CST, "Alf P. Steinbach" wrote:
>* Roland Pibinger:
>> AFAICS, you need to sup****t const and non-const arguments.
>
>Well, if conventional, straightforward notation is to be sup****ted 
>then until C++0x that leads to a combinatorial explosion, e.g. 63 = 
>2^(5+1)-1 constructor overloads for sup****t for 5 or fewer arguments, 
>and it's very rare that a non-const constructor argument makes sense.

Non-const constructor arguments (also non-const pointers) make sense
for a generic template. I have implemented a generic factory (creates
and owns objects). Its create functions sup****t up to 8 const and
non-const arguments. You just have to write a little code generation
tool ...

>Sup****ting the possibility self-destruction, or other early 
>destruction via an agency that is not the smart-pointer, is the main 
>point of CheckingPtr, which AutoNewPtr builds on.  For example, 
>objects that represent GUI objects often self-destruct ...  
>As another example, objects that represent e.g. files often enter a 
>zombie state (std::istream and std::ostream objects do).  

I'm not aware of those GUI frameworks (although I worked on Windows
for several years) nor of i/ostream zombie states. Anyway,
AutoNewPtr's main point, at least for me, is that it is "not
initialized with a raw pointer" and "takes responsibility for 'new'".


>
>Where you want a default-constructed pointee, the AutoNewPtr notation 
>is therefore to say that explicitly,
>
>   AutoNewPtr<T>  p( newNoArgs );    // Like p = new T;

The constructor syntax in general seems to be problematic.
AutoNewPtr<T> represents a pointer (and accesses T like a pointer) but
is constructed as if it were an object on the stack. Create functions
instead of constructors would be more consistent, e.g.:

AutoNewPtr<T>  p1 = createAutoNewPtr<T>(); // like p1 = new T
p1->dosomething();

AutoNewPtr<T>  p2;  // like p2 = 0

AutoNewPtr<T>  p3 = createAutoNewPtr<T>(arg); // like p3 = new T(arg)


>The deleter customization ability is the to-be-standard 
>std::default_delete mechanism, illustrated in the test code.

I've not been aware of 'default_delete' (frankly, I'm not interested
in C++ 0x).

I see at least two advantages of an AutoNewPtr-like template compared
to conventional 'smart pointers' (disregarding self-destructing
objects for the sake of argument):
- clear owner****p semantics, no transfer of owner****p
- only one call of operator new per created object is necessary
(object and ref-counter can be allocated together), i.e. the
efficiency of auto_ptr combined with the semantics of shared_ptr.


-- 
Roland Pibinger
"The best software is simple, elegant, and full of drama" - Grady Booch

      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 13 Posts in Topic:
ANN: AutoNewPtr (oh yes, yet another smartpointer)
"Alf P. Steinbach&qu  2008-05-11 09:42:27 
Re: ANN: AutoNewPtr (oh yes, yet another smartpointer)
=?ISO-8859-1?Q?Daniel_Kr=  2008-05-11 16:39:48 
Re: ANN: AutoNewPtr (oh yes, yet another smartpointer)
"Alf P. Steinbach&qu  2008-05-11 20:13:20 
Re: ANN: AutoNewPtr (oh yes, yet another smartpointer)
"Alf P. Steinbach&qu  2008-05-11 20:13:18 
Re: ANN: AutoNewPtr (oh yes, yet another smartpointer)
"Alf P. Steinbach&qu  2008-05-12 04:38:03 
Re: ANN: AutoNewPtr (oh yes, yet another smartpointer)
rpbg123@[EMAIL PROTECTED]  2008-05-12 09:27:13 
Re: ANN: AutoNewPtr (oh yes, yet another smartpointer)
Kai-Uwe Bux <jkherciue  2008-05-13 21:13:58 
Re: ANN: AutoNewPtr (oh yes, yet another smartpointer)
"Alf P. Steinbach&qu  2008-05-14 12:53:54 
Re: ANN: AutoNewPtr (oh yes, yet another smartpointer)
"Alf P. Steinbach&qu  2008-05-14 15:11:54 
Re: ANN: AutoNewPtr (oh yes, yet another smartpointer)
dizzy <dizzy@[EMAIL PR  2008-05-15 11:16:50 
Re: ANN: AutoNewPtr (oh yes, yet another smartpointer)
"Alf P. Steinbach&qu  2008-05-16 11:57:29 
Re: ANN: AutoNewPtr (oh yes, yet another smartpointer)
rpbg123@[EMAIL PROTECTED]  2008-05-16 17:29:51 
Re: ANN: AutoNewPtr (oh yes, yet another smartpointer)
"Alf P. Steinbach&qu  2008-05-18 02:43:50 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Oct 14 8:49:38 CDT 2008.