[squid-dev] [PATCH] Non-zeroing mempools
Kinkie
gkinkie at gmail.com
Sun Aug 23 22:22:15 UTC 2015
On Sun, Aug 23, 2015 at 9:16 PM, Alex Rousskov <
rousskov at measurement-factory.com> wrote:
> 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.
>
Sounds excellent to me.
> [ 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. ]
>
We can try adding that as an encouragement; won't fix the past but it may
help for the future.
> 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.
>
With private (on clang)
StoreMeta.cc:100:22: error: call to implicitly-deleted default constructor
of 'StoreMetaMD5'
result = new StoreMetaMD5;
^
../src/StoreMetaMD5.h:16:22: note: default constructor of 'StoreMetaMD5' is
implicitly deleted because base class 'StoreMeta' has an inaccessible
default constructor
class StoreMetaMD5 : public StoreMeta
^
--
Francesco
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squid-cache.org/pipermail/squid-dev/attachments/20150824/66724ecc/attachment.html>
More information about the squid-dev
mailing list