r3175 - in trunk/libmutil: include/libmutil source
erik at minisip.org
erik at minisip.org
Thu Feb 1 11:31:31 CET 2007
Author: erik
Date: 2007-02-01 11:31:30 +0100 (Thu, 01 Feb 2007)
New Revision: 3175
Modified:
trunk/libmutil/include/libmutil/MemObject.h
trunk/libmutil/source/MemObject.cxx
Log:
* getMemObjectNames has a new friend called getMemObjectNamesSummary
that works similarly, but reports the count of each object type
instead of reference count to each object. This is helpful
when detecting MObject leaks.
From the documentation:
Same as getMemObjectNames() except that it reports the objects
as a count for each type.
Example:
If getMemObjectNames would report the following objects:
Name Ref count
TypeA 2
TypeA 4
TypeB 1
TypeA <on stack>
TypeB 4
then this function will report:
Name Count
TypeA 3
TypeB 2
Modified: trunk/libmutil/include/libmutil/MemObject.h
===================================================================
--- trunk/libmutil/include/libmutil/MemObject.h 2007-02-01 10:02:03 UTC (rev 3174)
+++ trunk/libmutil/include/libmutil/MemObject.h 2007-02-01 10:31:30 UTC (rev 3175)
@@ -460,7 +460,26 @@
*/
LIBMUTIL_API minilist<std::string> getMemObjectNames();
+/**
+ * Same as getMemObjectNames() except that it reports the objects
+ * as a count for each type.
+ * Example:
+ * If getMemObjectNames would report the following objects:
+ * Name Ref count
+ * TypeA 2
+ * TypeA 4
+ * TypeB 1
+ * TypeA <stack>
+ * TypeB 4
+ * then this function will report:
+ * Name Count
+ * TypeA 3
+ * TypeB 2
+ */
+LIBMUTIL_API minilist<std::string> getMemObjectNamesSummary();
+
+
#endif
Modified: trunk/libmutil/source/MemObject.cxx
===================================================================
--- trunk/libmutil/source/MemObject.cxx 2007-02-01 10:02:03 UTC (rev 3174)
+++ trunk/libmutil/source/MemObject.cxx 2007-02-01 10:31:30 UTC (rev 3175)
@@ -188,3 +188,75 @@
#endif
}
+minilist<string> getMemObjectNamesSummary(){
+#ifdef MDEBUG
+ minilist<string> ret;
+ std::list<string> str; // unique names
+ std::list<int> count; // count for corresponding name in str
+ std::list<string>::iterator si;
+ std::list<string>::iterator js;
+ std::list<int>::iterator jc;
+ global.lock();
+ // get list of unique names, and count
+ int i;
+ for (i=0; i< objs.size(); i++){
+ string oname = objs[i]->getMemObjectType();
+ bool found=false;
+ for ( jc=count.begin(), js=str.begin(); js!=str.end(); jc++, js++ ){
+ if (*js==oname){
+ (*jc)=*jc+1;
+ found=true;
+ break;
+ }
+ }
+ if (!found){
+ str.push_back(oname);
+ count.push_back(1);
+ }
+
+ }
+
+ // Bubble sort to arrange names is ascending order
+ bool done;
+ do {
+ done=true;
+ std::list<int>::iterator jc_last;
+ std::list<string>::iterator js_last;
+ jc_last = count.begin();
+ js_last = str.begin();
+ js=str.begin();
+ jc=count.begin();
+ if (js!=str.end()){ //start from second item
+ js++;
+ jc++;
+ }
+
+ for ( ; js!=str.end(); jc++, js++, jc_last++, js_last++){
+ if ( (*jc) < (*jc_last) ){
+ int tmpc=*jc;
+ *jc = *jc_last;
+ *jc_last=tmpc;
+
+ string tmps=*js;
+ *js = *js_last;
+ *js_last=tmps;
+ done=false;
+
+ }
+ }
+ }while (!done);
+
+ for (jc=count.begin(), js=str.begin(); js!=str.end(); jc++, js++){
+ ret.push_back( *js + " " + itoa( *jc ) );
+ }
+
+ global.unlock();
+ return ret;
+#else
+ minilist<string> ret;
+ return ret;
+#endif
+}
+
+
+
More information about the Minisip-devel
mailing list