Confirmed users
1,345
edits
Nnethercote (talk | contribs) |
Nnethercote (talk | contribs) |
||
| Line 160: | Line 160: | ||
Things to note about <tt>SizeOfIncludingThis</tt>. | Things to note about <tt>SizeOfIncludingThis</tt>. | ||
* <tt>D::SizeOfIncludingThis</tt> is identical to <tt>B::SizeOfIncludingThis</tt>. You might think that <tt>D</tt> could just inherit <tt>SizeOfIncludingThis</tt> from <tt>B</tt>. In some cases this works, but there's a lot of C++ subtlety involving the <tt>aMallocSizeOf(this)</tt> and whether <tt>this</tt> actually points to the start of the allocated object or somewhere in it's middle. This is doubly true if <tt>D</tt> features multiple inheritance. So, if in doubt, define <tt>D::SizeOfIncludingThis</tt> and you should be safe. | * <tt>D::SizeOfIncludingThis</tt> is identical to <tt>B::SizeOfIncludingThis</tt>. You might think that <tt>D</tt> could just inherit <tt>SizeOfIncludingThis</tt> from <tt>B</tt>. In some cases this works, but there's a lot of C++ subtlety involving the <tt>aMallocSizeOf(this)</tt> and whether <tt>this</tt> actually points to the start of the allocated object or somewhere in it's middle. This is doubly true if <tt>D</tt> features multiple inheritance. And if <tt>aMallocSizeOf</tt> is passed a pointer that doesn't point to the start of an object it will give bogus results or even crash. So, if in doubt, define <tt>D::SizeOfIncludingThis</tt> and you should be safe. | ||
* The <tt>MOZ_OVERRIDE</tt> annotations say that <tt>D</tt>'s methods override the corresponding methods in <tt>B</tt>. On supporting compilers it gets expanded to the <tt>override</tt> keyword. It helps prevent accidentally having small differences in the function signatures (e.g. forgetting a <tt>const</tt>) that prevent the overriding from happening. | * The <tt>MOZ_OVERRIDE</tt> annotations say that <tt>D</tt>'s methods override the corresponding methods in <tt>B</tt>. On supporting compilers it gets expanded to the <tt>override</tt> keyword. It helps prevent accidentally having small differences in the function signatures (e.g. forgetting a <tt>const</tt>) that prevent the overriding from happening. | ||