[squid-dev] [PATCH] Non-zeroing mempools

Alex Rousskov rousskov at measurement-factory.com
Sun Aug 23 19:16:45 UTC 2015


On 08/19/2015 11:11 PM, Amos Jeffries wrote:

> * when adding a new constructor ensure the big-5 operators (ctor, dtor,
> assign, emplace, emplace-assign) are all present. Even if they use "=
> default"

IMO, the above rule is wrong because it forces developers to add
absolutely unnecessary code in many cases (unnecessary from any points
of view, even code readability and documentation).


A better set of rules would say something like this:

Big3 methods: copy constructor, destructor, and assignment operator.
Move methods: move constructor and move assignment operator.

0. If the class works well without any of the Big3 methods, do not
define any of the Big3 methods.

1. If you have to define one of Big3, declare all of Big3.

2. If your class has a non-default destructor implementation, you may
decide to define one of the Move methods. If you define one Move method,
declare the other Move method as well.

3. Whenever you declare a method, use a "= default" declaration when the
default method implementation matches your needs and use a "= delete"
declaration when using the declared method is prohibited.


[ I also like the "Rule of 0" that states that "if you specify any of
the default members, then your class must deal exclusively with a single
resource", but we probably have too many violations of this rule and too
many raw pointers floating around to enforce it. ]


AFAICT, StoreMeta in the last patch does not satisfy rule #3. To satisfy
that rule, StoreMeta should:

* use "= default" for the virtual destructor

* use either "= default" or "= delete" for the copy constructor and the
assignment operator.


> Omitting emplace and implementing the others as protected for
> completeness' sake.

Why protected?

* Making default constructor protected is the same as keeping it public
because the class is abstract (nobody can create a StoreMeta object).

* If you want to prohibit copying, use "= delete" for copy constructor
and assignment operator. Given the class use of raw pointers, deleting
sounds like a good idea, but I did not study this class usage in detail.
In general, prohibiting dangerous operations is better than allowing
them so if "= delete" works well, we should use it.


HTH,

Alex.



More information about the squid-dev mailing list