Last Comment Bug 674284 - Add nsTArray::SizeOf
: Add nsTArray::SizeOf
Status: RESOLVED FIXED
[MemShrink]
:
Product: Core
Classification: Components
Component: XPCOM (show other bugs)
: Trunk
: x86 Windows 7
: -- normal (vote)
: mozilla8
Assigned To: Kyle Huey [:khuey] (khuey@mozilla.com)
:
Mentors:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-07-26 10:57 PDT by Kyle Huey [:khuey] (khuey@mozilla.com)
Modified: 2011-08-02 08:38 PDT (History)
4 users (show)
khuey: in‑testsuite-
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
Patch (794 bytes, patch)
2011-07-26 10:57 PDT, Kyle Huey [:khuey] (khuey@mozilla.com)
benjamin: review+
Details | Diff | Review

Description Kyle Huey [:khuey] (khuey@mozilla.com) 2011-07-26 10:57:31 PDT
Created attachment 548525 [details] [diff] [review]
Patch

For about:memory reporting usage.
Comment 1 Kyle Huey [:khuey] (khuey@mozilla.com) 2011-08-01 05:14:06 PDT
http://hg.mozilla.org/mozilla-central/rev/030c419226ed
Comment 2 Marco Bonardo [::mak] 2011-08-01 05:33:05 PDT
this has been backed out
http://hg.mozilla.org/mozilla-central/rev/9517e7652dec
Comment 3 neil@parkwaycc.co.uk 2011-08-01 07:26:55 PDT
Comment on attachment 548525 [details] [diff] [review]
Patch

>+  // @return The amount of memory taken used by this nsTArray, not including
>+  // sizeof(this)
>+  size_t SizeOf() const {
>+    return Capacity() * sizeof(elem_type) + sizeof(mHdr);
Except the mHdr is shared between non-auto nsTArrays...
Comment 4 Kyle Huey [:khuey] (khuey@mozilla.com) 2011-08-01 09:26:17 PDT
(In reply to comment #3)
> Comment on attachment 548525 [details] [diff] [review] [diff] [details] [review]
> Patch
> 
> >+  // @return The amount of memory taken used by this nsTArray, not including
> >+  // sizeof(this)
> >+  size_t SizeOf() const {
> >+    return Capacity() * sizeof(elem_type) + sizeof(mHdr);
> Except the mHdr is shared between non-auto nsTArrays...

That's only true if the nsTArray is empty, no?
Comment 5 Kyle Huey [:khuey] (khuey@mozilla.com) 2011-08-01 09:32:50 PDT
Comment on attachment 548525 [details] [diff] [review]
Patch

This bounced with

../../../dist/include/nsTArray.h: In member function 'size_t nsTArray<E, Alloc>::SizeOf() const':
../../../dist/include/nsTArray.h:436:21: error: there are no arguments to 'Capacity' that depend on a template parameter, so a declaration of 'Capacity' must be available
../../../dist/include/nsTArray.h:436:21: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
../../../dist/include/nsTArray.h:436:52: error: 'mHdr' was not declared in this scope

Not quite sure what to make of these ... it looks like base class members aren't in scope?
Comment 6 Benjamin Smedberg [:bsmedberg] 2011-08-01 10:01:05 PDT
You need this->Capacity. Bare names are not in scope in template classes that inherit from other templated classes. C++ is weird like that.
Comment 7 Kyle Huey [:khuey] (khuey@mozilla.com) 2011-08-02 08:38:01 PDT
Added the 'this' qualifiers.

http://hg.mozilla.org/mozilla-central/rev/bd93ca20e1fd

Note You need to log in before you can comment on or make changes to this bug.