summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-04-01 21:12:51 +0000
committerrubidium <rubidium@openttd.org>2008-04-01 21:12:51 +0000
commit8e8362799187dab20c81aca4f19b6f6a218306be (patch)
tree8b8b47a627fbcb06ab1faeb36727a71765a27279 /src/core
parent81b6125ac2adf4aeac327aa6a80cced3f4c84f35 (diff)
downloadopenttd-8e8362799187dab20c81aca4f19b6f6a218306be.tar.xz
(svn r12536) -Codechange: some stack allocations were too large for NDS, so use the SmallStackSafeStackAlloc wrapper. Allocate on the stack by default and on the heap for NDS (or other devices that have a very small stack).
Diffstat (limited to 'src/core')
-rw-r--r--src/core/alloc_func.hpp25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/core/alloc_func.hpp b/src/core/alloc_func.hpp
index a2cae3e3d..57a5fc3d4 100644
--- a/src/core/alloc_func.hpp
+++ b/src/core/alloc_func.hpp
@@ -107,9 +107,11 @@ struct SmallStackSafeStackAlloc {
#else
/** Storing it on the heap */
T *data;
+ /** The length (in elements) of data in this allocator. */
+ size_t len;
/** Allocating the memory */
- SmallStackSafeStackAlloc() : data(MallocT<T>(length)) {}
+ SmallStackSafeStackAlloc() : data(MallocT<T>(length)), len(length) {}
/** And freeing when it goes out of scope */
~SmallStackSafeStackAlloc() { free(data); }
#endif
@@ -118,7 +120,26 @@ struct SmallStackSafeStackAlloc {
* Gets a pointer to the data stored in this wrapper.
* @return the pointer.
*/
- operator T* () { return data; }
+ inline operator T* () { return data; }
+
+ /**
+ * Gets a pointer to the data stored in this wrapper.
+ * @return the pointer.
+ */
+ inline T* operator -> () { return data; }
+
+ /**
+ * Gets a pointer to the last data element stored in this wrapper.
+ * @note needed because endof does not work properly for pointers.
+ * @return the 'endof' pointer.
+ */
+ inline T* EndOf() {
+#if !defined(__NDS__)
+ return endof(data);
+#else
+ return &data[len];
+#endif
+ }
};
#endif /* ALLOC_FUNC_HPP */