summaryrefslogtreecommitdiff
path: root/yapf/fixedsizearray.hpp
diff options
context:
space:
mode:
authorKUDr <kudr@openttd.org>2006-11-18 19:20:47 +0000
committerKUDr <kudr@openttd.org>2006-11-18 19:20:47 +0000
commit9b81f084af2a19da3487fa747bc40f2c4b876845 (patch)
tree0dcbe68a8fa0166ef30d7a7f8870a502837bfa23 /yapf/fixedsizearray.hpp
parent3f64e50fc9a8f336fae1e59adabf604d8778cd4e (diff)
downloadopenttd-9b81f084af2a19da3487fa747bc40f2c4b876845.tar.xz
(svn r7210) -CodeChange: [YAPF] the global cache object is now not destroyed/recreated whenever the cache is invalidated. It now supports Flush() method that is used instead. It should also fix mem-leak warning produced by valgrind (Tron)
Diffstat (limited to 'yapf/fixedsizearray.hpp')
-rw-r--r--yapf/fixedsizearray.hpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/yapf/fixedsizearray.hpp b/yapf/fixedsizearray.hpp
index 5d6c3b313..48b177f3c 100644
--- a/yapf/fixedsizearray.hpp
+++ b/yapf/fixedsizearray.hpp
@@ -51,12 +51,21 @@ struct CFixedSizeArrayT {
// release one reference to the shared block
if ((--RefCnt()) > 0) return; // and return if there is still some owner
+ Clear();
+ // free the memory block occupied by items
+ free(((int8*)m_items) - ThdrSize);
+ m_items = NULL;
+ }
+
+ /** Clear (destroy) all items */
+ FORCEINLINE void Clear()
+ {
// walk through all allocated items backward and destroy them
for (Titem* pItem = &m_items[Size() - 1]; pItem >= m_items; pItem--) {
pItem->~Titem_();
}
- free(((int8*)m_items) - ThdrSize);
- m_items = NULL;
+ // number of items become zero
+ SizeRef() = 0;
}
protected: