Monday, October 5, 2015

FeedaMail: Comments for Sutter̢۪s Mill

feedamail.com Comments for Sutter's Mill

Comment on My talk at CppCon by Daniel Teske

So I looked through the paper in the core guidelines paper and all of that looks pretty fantastic. I’d love to try that out on Qt to see if the rules and the tool are suffiecently smart that the effort is reasonable.

One pattern, that is very common in Qt, is that parents take ownership of their children. To give a concrete but example, imagine a class like this: (Drastically simplified to only the memory management.)

class Thing
{
Thing(Thing *parent = 0)
{
if (parent)
parent->children.append(this);
}
~Thing()
{
for (auto child, children)
delete child;
}
vector children;
};

Now the semantics of that are, pretty obvious. If a thing has a parent, then that parent takes care of deleting its children. Otherwise the user has to take care of that Thing.

In pratice, for e.g. widgets in windows, pretty much everything has a parent and thus is automatically deleted, except for top level windows. So it does actually work pretty well.

Now, since Qt values source and binary compability a lot, we can’t really change the API, but still I would like to change it so that the tools can detect memory errors in Qt code.

The first step would probably to uses two constructors:
Thing() // needs to be assigned to a owner, or stack allocated.
Thing(NotNull) // needs to be assigend to a raw pointer

Looking at the paper I couldn’t find any way to express the comments in code or annotations for the tools though.

Any thoughs on this?

Read More »
 
Delievered to you by Feedamail.
Unsubscribe