alloc_type.hpp

Go to the documentation of this file.
00001 /* $Id: alloc_type.hpp 14949 2009-01-10 00:31:47Z rubidium $ */
00002 
00005 #ifndef ALLOC_TYPE_HPP
00006 #define ALLOC_TYPE_HPP
00007 
00008 #include "alloc_func.hpp"
00009 
00019 template <typename T, size_t length>
00020 struct SmallStackSafeStackAlloc {
00021 #if !defined(__NDS__)
00022 
00023   T data[length];
00024 #else
00025 
00026   T *data;
00028   size_t len;
00029 
00031   SmallStackSafeStackAlloc() : data(MallocT<T>(length)), len(length) {}
00032 
00034   ~SmallStackSafeStackAlloc()
00035   {
00036     free(data);
00037   }
00038 #endif
00039 
00044   FORCEINLINE operator T *()
00045   {
00046     return data;
00047   }
00048 
00053   FORCEINLINE T *operator -> ()
00054   {
00055     return data;
00056   }
00057 
00063   FORCEINLINE T *EndOf()
00064   {
00065 #if !defined(__NDS__)
00066     return endof(data);
00067 #else
00068     return &data[len];
00069 #endif
00070   }
00071 };
00072 
00077 class ZeroedMemoryAllocator
00078 {
00079 public:
00080   ZeroedMemoryAllocator() {}
00081   virtual ~ZeroedMemoryAllocator() {}
00082 
00088   FORCEINLINE void *operator new(size_t size) { return CallocT<byte>(size); }
00089 
00095   FORCEINLINE void *operator new[](size_t size) { return CallocT<byte>(size); }
00096 
00105   FORCEINLINE void operator delete(void *ptr, size_t size) { free(ptr); }
00106 
00115   FORCEINLINE void operator delete[](void *ptr, size_t size) { free(ptr); }
00116 };
00117 
00118 #endif /* ALLOC_TYPE_HPP */

Generated on Mon Feb 16 23:12:06 2009 for openttd by  doxygen 1.5.6