Platform/Memory Reporting: Difference between revisions

Jump to navigation Jump to search
m
Replace nsMallocSizeOfFun with mozilla::MallocSizeOf
m (Replace nsMallocSizeOfFun with mozilla::MallocSizeOf)
Line 52: Line 52:
Here are what the measurement functions (yes, functions) should look like for this class.
Here are what the measurement functions (yes, functions) should look like for this class.


     size_t MyString::SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const {
     size_t MyString::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const {
         return aMallocSizeOf(mBuffer);
         return aMallocSizeOf(mBuffer);
     }
     }
     size_t MyString::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const {
     size_t MyString::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const {
         return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
         return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
     }
     }
Line 73: Line 73:
* The size is not computed analytically.  For example, <tt>sizeof</tt> doesn't appear anywhere.  This is a good thing, because computing sizes analytically doesn't count slop, and it is much more error-prone than using <tt>moz_malloc_usable_size</tt>.
* The size is not computed analytically.  For example, <tt>sizeof</tt> doesn't appear anywhere.  This is a good thing, because computing sizes analytically doesn't count slop, and it is much more error-prone than using <tt>moz_malloc_usable_size</tt>.


* They are flexible and integrate well with DMD.  The <tt>aMallocSizeOf</tt> parameter allows <tt>nsMallocSizeOfFun</tt> functions with DMD-specific hooks to be passed in when they are used by memory reporters, but functions without such hooks (such as <tt>moz_malloc_size_of</tt>) can also be passed in when they are used in other circumstances.
* They are flexible and integrate well with DMD.  The <tt>aMallocSizeOf</tt> parameter allows <tt>mozilla::MallocSizeOf</tt> functions with DMD-specific hooks to be passed in when they are used by memory reporters, but functions without such hooks (such as <tt>moz_malloc_size_of</tt>) can also be passed in when they are used in other circumstances.


Some other things to note:
Some other things to note:
Line 106: Line 106:
   NS_IMPL_ISUPPORTS1(MyStringReporter, nsIMemoryReporter)
   NS_IMPL_ISUPPORTS1(MyStringReporter, nsIMemoryReporter)


Note that <tt>MOZ_DEFINE_MALLOC_SIZE_OF</tt> defines a function of type <tt>nsMallocSizeOfFun</tt> that is specific to this memory reporter (and will be identified as such in DMD's output).  And <tt>MOZ_COLLECT_REPORT</tt> is a macro that makes things a bit shorter.
Note that <tt>MOZ_DEFINE_MALLOC_SIZE_OF</tt> defines a function of type <tt>mozilla::MallocSizeOf</tt> that is specific to this memory reporter (and will be identified as such in DMD's output).  And <tt>MOZ_COLLECT_REPORT</tt> is a macro that makes things a bit shorter.


=== An Example Involving Inheritance ===
=== An Example Involving Inheritance ===
Confirmed users
43

edits

Navigation menu