diff engine/core/util/resource/pool.cpp @ 147:fb6ccb367dd1

Added just some docs and a sanityCheck against the difficult to find bugs of the location classes. So if memory usage/load time goes through the roof, try logging 'pool' messages.
author phoku@33b003aa-7bff-0310-803a-e67f0ece8222
date Thu, 09 Oct 2008 13:36:13 +0000
parents 54b3984e1afc
children 72c25cc27d8b
line wrap: on
line diff
--- a/engine/core/util/resource/pool.cpp	Thu Oct 09 12:36:21 2008 +0000
+++ b/engine/core/util/resource/pool.cpp	Thu Oct 09 13:36:13 2008 +0000
@@ -48,6 +48,7 @@
 	Pool::~Pool() {
 		FL_LOG(_log, LMsg("Pool destroyed: ") << m_name);
 		printStatistics();
+		sanityCheck();
 		clear();
 		std::vector<ResourceLoader*>::iterator loader;
 		for (loader = m_loaders.begin(); loader != m_loaders.end(); loader++) {
@@ -225,4 +226,24 @@
 		FL_LOG(_log, LMsg("Pool locked     =") << amount);
 		FL_LOG(_log, LMsg("Pool total size =") << m_entries.size());
 	}
+
+	void Pool::sanityCheck() {
+		// It is easy to mess up the important consistent
+		// less-than operator for the location classes.
+		// This will check if according to the '==' operator 
+		// entries are duplicate (=memory leaks).
+		// Slow and inaccurate. But should barf at real messups.
+		for(unsigned i = 0; i != m_entries.size(); ++i) {
+			int count = 0;
+			for(unsigned j = i+1; j < m_entries.size(); ++j) {
+				if( *m_entries[i]->location == *m_entries[j]->location )
+					count ++;
+			}
+			if( 0 == count )
+				continue;
+			FL_WARN(_log, LMsg("Multiple entries: ") << m_entries[i]->location->getFilename()
+			  << " #entries = " << (count+1) );
+		}
+	}
+
 }