Platform/Memory Reporting: Difference between revisions

Line 111: Line 111:
=== An Example Involving Inheritance ===
=== An Example Involving Inheritance ===


Things are a little trickier when inheritance is involved.  Every sub-class needs to have its own implementation of <tt>SizeOfExcludingThis</tt>.
Things are a little trickier when inheritance is involved.  Every sub-class needs to have its own implementation of <tt>SizeOfExcludingThis</tt>. An example:


   class B {
   class B {
Line 130: Line 130:
     {
     {
         size_t n = B::SizeOfExcludingThis(aMallocSizeOf);
         size_t n = B::SizeOfExcludingThis(aMallocSizeOf);
         n += ...  // measure D-specific fields
         n += ...  // measure things pointed to by D-specific fields
        return n;
     }
     }
   };
   };
Line 142: Line 143:
* The <tt>NS_MUST_OVERRIDE</tt> is an annotation that indicates that this function must be overridden by any sub-classes.  It's used by some static analysis tools.  Currently these tools aren't running, but they might in the future, and it's a useful piece of documentation.
* The <tt>NS_MUST_OVERRIDE</tt> is an annotation that indicates that this function must be overridden by any sub-classes.  It's used by some static analysis tools.  Currently these tools aren't running, but they might in the future, and it's a useful piece of documentation.


* The <tt>MOZ_OVERRIDE</tt> annotation says that <tt>D::SizeOfExcludingThis</tt> overrides the corresponding function in <tt>B</tt>.  On supporting compilers it gets expanded to the <tt>override</tt> keyword.  It's useful to avoid accidentally having small mismatches in the function signatures that prevent the overriding from happening.   
* The <tt>MOZ_OVERRIDE</tt> annotation says that <tt>D::SizeOfExcludingThis</tt> overrides the corresponding function 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 definitions of <tt>SizeOfIncludingThis</tt>, if needed, are straightforward and like the ones above.
* The definitions of <tt>SizeOfIncludingThis</tt>, if needed, are straightforward and like the ones above.
Confirmed users
1,345

edits