Confirmed users
1,345
edits
Nnethercote (talk | contribs) |
Nnethercote (talk | contribs) |
||
Line 85: | Line 85: | ||
And here's how you'd write a memory reporter if there was a single global MyString object. | And here's how you'd write a memory reporter if there was a single global MyString object. | ||
MyString *gMyString; | MyString *gMyString; | ||
class MyStringReporter MOZ_FINAL : public MemoryUniReporter | |||
{ | { | ||
public: | |||
MyStringReporter() | |||
// BTW: If gMyString wasn't a pointer, you'd use | : MemoryUniReporter("mystring", KIND_HEAP, UNITS_BYTES, | ||
"Memory used for MyString.") | |||
{} | |||
private: | |||
int64_t Amount() MOZ_OVERRIDE | |||
{ | |||
// BTW: If gMyString wasn't a pointer, you'd use | |||
// |gMyString.SizeOfExcludingThis(MallocSizeOf)| instead. | |||
return gMyString->SizeOfIncludingThis(MallocSizeOf); | |||
} | |||
}; | |||
<tt>MemoryUniReporter</tt> is a class that avoids most of the boilerplate code, and can be | |||
used for most uni-reporters. Note that <tt>MallocSizeOf</tt> is a member of <tt>MemoryUniReporter</tt>. It is a function of type <tt>nsMallocSizeOfFun</tt> that is specific to this memory reporter (and will be identified as such in DMD's output). | |||
=== An Example Involving Inheritance === | === An Example Involving Inheritance === |