From 571ba97f56a3b466f3ae641fab373f98ff85b9a7 Mon Sep 17 00:00:00 2001 From: rubidium Date: Tue, 1 Apr 2008 21:12:51 +0000 Subject: (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). --- src/core/alloc_func.hpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src/core/alloc_func.hpp') 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(length)) {} + SmallStackSafeStackAlloc() : data(MallocT(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 */ -- cgit v1.2.3-70-g09d2