src/core/alloc_func.hpp
changeset 8798 2c6062ce7dba
parent 8537 14be8ee6a268
child 8925 e0d37ce1eba8
equal deleted inserted replaced
8797:6cc3e9dec506 8798:2c6062ce7dba
   105 	/** Storing the data on the stack */
   105 	/** Storing the data on the stack */
   106 	T data[length];
   106 	T data[length];
   107 #else
   107 #else
   108 	/** Storing it on the heap */
   108 	/** Storing it on the heap */
   109 	T *data;
   109 	T *data;
       
   110 	/** The length (in elements) of data in this allocator. */
       
   111 	size_t len;
   110 
   112 
   111 	/** Allocating the memory */
   113 	/** Allocating the memory */
   112 	SmallStackSafeStackAlloc() : data(MallocT<T>(length)) {}
   114 	SmallStackSafeStackAlloc() : data(MallocT<T>(length)), len(length) {}
   113 	/** And freeing when it goes out of scope */
   115 	/** And freeing when it goes out of scope */
   114 	~SmallStackSafeStackAlloc() { free(data); }
   116 	~SmallStackSafeStackAlloc() { free(data); }
   115 #endif
   117 #endif
   116 
   118 
   117 	/**
   119 	/**
   118 	 * Gets a pointer to the data stored in this wrapper.
   120 	 * Gets a pointer to the data stored in this wrapper.
   119 	 * @return the pointer.
   121 	 * @return the pointer.
   120 	 */
   122 	 */
   121 	operator T* () { return data; }
   123 	inline operator T* () { return data; }
       
   124 
       
   125 	/**
       
   126 	 * Gets a pointer to the data stored in this wrapper.
       
   127 	 * @return the pointer.
       
   128 	 */
       
   129 	inline T* operator -> () { return data; }
       
   130 
       
   131 	/**
       
   132 	 * Gets a pointer to the last data element stored in this wrapper.
       
   133 	 * @note needed because endof does not work properly for pointers.
       
   134 	 * @return the 'endof' pointer.
       
   135 	 */
       
   136 	inline T* EndOf() {
       
   137 #if !defined(__NDS__)
       
   138 		return endof(data);
       
   139 #else
       
   140 		return &data[len];
       
   141 #endif
       
   142 	}
   122 };
   143 };
   123 
   144 
   124 #endif /* ALLOC_FUNC_HPP */
   145 #endif /* ALLOC_FUNC_HPP */