summaryrefslogtreecommitdiff
path: root/src/core/pool_type.hpp
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2011-02-09 18:55:51 +0000
committersmatz <smatz@openttd.org>2011-02-09 18:55:51 +0000
commitfbfb0ffbf24b7ea2630b4b3caee63d09964da75b (patch)
tree67be7735e5e0c92c21dd572a6349b16e62d88f23 /src/core/pool_type.hpp
parent67cbee4f6476874e5a657412b9ec0033a443562f (diff)
downloadopenttd-fbfb0ffbf24b7ea2630b4b3caee63d09964da75b.tar.xz
(svn r22041) -Codechange: add a check that we called PoolItem::CanAllocateItem() before actually allocating it
Diffstat (limited to 'src/core/pool_type.hpp')
-rw-r--r--src/core/pool_type.hpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/core/pool_type.hpp b/src/core/pool_type.hpp
index 49876976f..395aa8438 100644
--- a/src/core/pool_type.hpp
+++ b/src/core/pool_type.hpp
@@ -32,7 +32,9 @@ struct Pool {
size_t first_free; ///< No item with index lower than this is free (doesn't say anything about this one!)
size_t first_unused; ///< This and all higher indexes are free (doesn't say anything about first_unused-1 !)
size_t items; ///< Number of used indexes (non-NULL)
-
+#ifdef OTTD_ASSERT
+ size_t checked; ///< Number of items we checked for
+#endif /* OTTD_ASSERT */
bool cleaning; ///< True if cleaning pool (deleting all items)
Titem **data; ///< Pointer to array of pointers to Titem
@@ -69,7 +71,11 @@ struct Pool {
*/
FORCEINLINE bool CanAllocate(size_t n = 1)
{
- return this->items <= Tmax_size - n;
+ bool ret = this->items <= Tmax_size - n;
+#ifdef OTTD_ASSERT
+ this->checked = ret ? n : 0;
+#endif /* OTTD_ASSERT */
+ return ret;
}
/**