[webkit-dev] Ptr<T>

Mike Marchywka marchywka at hotmail.com
Wed Aug 11 09:44:16 PDT 2010




----------------------------------------
> From: darin at apple.com
> Date: Wed, 11 Aug 2010 09:12:29 -0700
> To: eric at webkit.org
> CC: webkit-dev at lists.webkit.org
> Subject: Re: [webkit-dev] Ptr
>
> On Aug 7, 2010, at 8:59 PM, Eric Seidel wrote:
>
> > How about we add a Ptr (or WeakPtr or AutoNull or whatever)


Using java all the time, ref counted pointers annoy me. 
And being a memory nut, I always hope we can do clever stuff
with raw pointers later.

>
> I worked on another project years ago where they had a template like this. The issue is with a variety of built-in data types, not specific to pointers. Any built-in data type such as a pointer, integer, or floating point number where it's not initialized by default can instead be initialized like this:
>
> , m_member()
>
> That syntax will zero-initialize it. So if you have a template like this you can use it to take care of zero-initialization for any of these types. (For integers you can even go further and have the template specify the initial value which means you won’t have to repeat that value in multiple constructors.)

One more general problem I've had is with design assumptions getting forgotten.
More generous use of asserts would keep memories clear and not impact release builds.
Presumably you could put assert(foo==0) somewhere if you ever rely on initial state?
This is of course not definitive as a lot of memory could be zero by default.
Just a thought- asserts at bottom of ctor should be easy to remember and you can
put assert in with each new member or something. 






>
> So much for the up-side of a template like this.
>
> The downside is that the object does not have the type we might think it does. Even if we add assignment operators, conversion constructors and operators in both directions, it can still give us an unpleasant result in any context where overloading is involved, such as calling an overloaded function, and we might need an explicit function to get the actual scalar value, analogous to the get function we use on smart pointer.
>
> I’m not sure if in practice this “initialize me” template will improve things much; remembering to use it is not all that much easier than remembering to initialize in constructors, but I don’t object strongly to the notion.
>
> -- Darin
>
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev
 		 	   		  


More information about the webkit-dev mailing list