Platform/Memory Reporting: Difference between revisions

Jump to navigation Jump to search
Line 112: Line 112:


Sometimes you may need variations on the above forms.  For example, if you have a function that just measures one member <tt>Foo</tt> of an object, it might be called <tt>SizeOfFoo</tt>.  Try to make the names descriptive enough that it's clear what's being measured.
Sometimes you may need variations on the above forms.  For example, if you have a function that just measures one member <tt>Foo</tt> of an object, it might be called <tt>SizeOfFoo</tt>.  Try to make the names descriptive enough that it's clear what's being measured.
Sometimes you might want to split the measurements of an object into two or more numbers, e.g. because you want to show them separately in about:memory.  In which case just return the multiple values by reference, like this:
  void FooBar::SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf,
                                  size_t *foo, size_t* bar) const;
Alternatively, you could create a struct:
  struct FooBarStats {
      size_t foo;
      size_t bar;
  }
  void FooBar::SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf,
                                  FooBarStats *stats) const;
You could even put the <tt>nsMallocSizeOfFun</tt> in <code>FooBarStats</code> to reduce the number of arguments.


Sometimes it's difficult and/or not worth measuring every member of an object of in a <tt>Foo::SizeOfExcludingThis</tt> method.  This is ok, but it's worth adding a comment explaining this to the method.
Sometimes it's difficult and/or not worth measuring every member of an object of in a <tt>Foo::SizeOfExcludingThis</tt> method.  This is ok, but it's worth adding a comment explaining this to the method.
Confirmed users
1,345

edits

Navigation menu