Mercurial > fife-parpg
comparison 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 |
comparison
equal
deleted
inserted
replaced
146:54b3984e1afc | 147:fb6ccb367dd1 |
---|---|
46 } | 46 } |
47 | 47 |
48 Pool::~Pool() { | 48 Pool::~Pool() { |
49 FL_LOG(_log, LMsg("Pool destroyed: ") << m_name); | 49 FL_LOG(_log, LMsg("Pool destroyed: ") << m_name); |
50 printStatistics(); | 50 printStatistics(); |
51 sanityCheck(); | |
51 clear(); | 52 clear(); |
52 std::vector<ResourceLoader*>::iterator loader; | 53 std::vector<ResourceLoader*>::iterator loader; |
53 for (loader = m_loaders.begin(); loader != m_loaders.end(); loader++) { | 54 for (loader = m_loaders.begin(); loader != m_loaders.end(); loader++) { |
54 delete (*loader); | 55 delete (*loader); |
55 } | 56 } |
223 } | 224 } |
224 } | 225 } |
225 FL_LOG(_log, LMsg("Pool locked =") << amount); | 226 FL_LOG(_log, LMsg("Pool locked =") << amount); |
226 FL_LOG(_log, LMsg("Pool total size =") << m_entries.size()); | 227 FL_LOG(_log, LMsg("Pool total size =") << m_entries.size()); |
227 } | 228 } |
229 | |
230 void Pool::sanityCheck() { | |
231 // It is easy to mess up the important consistent | |
232 // less-than operator for the location classes. | |
233 // This will check if according to the '==' operator | |
234 // entries are duplicate (=memory leaks). | |
235 // Slow and inaccurate. But should barf at real messups. | |
236 for(unsigned i = 0; i != m_entries.size(); ++i) { | |
237 int count = 0; | |
238 for(unsigned j = i+1; j < m_entries.size(); ++j) { | |
239 if( *m_entries[i]->location == *m_entries[j]->location ) | |
240 count ++; | |
241 } | |
242 if( 0 == count ) | |
243 continue; | |
244 FL_WARN(_log, LMsg("Multiple entries: ") << m_entries[i]->location->getFilename() | |
245 << " #entries = " << (count+1) ); | |
246 } | |
247 } | |
248 | |
228 } | 249 } |