summaryrefslogtreecommitdiff
path: root/src/helpers.hpp
diff options
context:
space:
mode:
authorKUDr <kudr@openttd.org>2007-01-11 17:29:39 +0000
committerKUDr <kudr@openttd.org>2007-01-11 17:29:39 +0000
commit33be1ecfb1a9056b027d50d7b558cff87c5b744d (patch)
treed644a3831ca0947198b191fa3e4e8973d3a9786e /src/helpers.hpp
parent91ff74641060445dc1647bbf05baeb03b45c3099 (diff)
downloadopenttd-33be1ecfb1a9056b027d50d7b558cff87c5b744d.tar.xz
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
Diffstat (limited to 'src/helpers.hpp')
-rw-r--r--src/helpers.hpp18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/helpers.hpp b/src/helpers.hpp
index b13fc25d4..14b6056b3 100644
--- a/src/helpers.hpp
+++ b/src/helpers.hpp
@@ -10,24 +10,24 @@
/** When allocating using malloc/calloc in C++ it is usually needed to cast the return value
* from void* to the proper pointer type. Another alternative would be MallocT<> as follows */
-template <typename T> FORCEINLINE bool MallocT(T** t_ptr, size_t num_elements)
+template <typename T> FORCEINLINE T* MallocT(size_t num_elements)
{
- *t_ptr = (T*)malloc(num_elements * sizeof(T));
- return (*t_ptr != NULL);
+ T *t_ptr = (T*)malloc(num_elements * sizeof(T));
+ return t_ptr;
}
/** When allocating using malloc/calloc in C++ it is usually needed to cast the return value
* from void* to the proper pointer type. Another alternative would be MallocT<> as follows */
-template <typename T> FORCEINLINE bool CallocT(T** t_ptr, size_t num_elements)
+template <typename T> FORCEINLINE T* CallocT(size_t num_elements)
{
- *t_ptr = (T*)calloc(num_elements, sizeof(T));
- return (*t_ptr != NULL);
+ T *t_ptr = (T*)calloc(num_elements, sizeof(T));
+ return t_ptr;
}
/** When allocating using malloc/calloc in C++ it is usually needed to cast the return value
* from void* to the proper pointer type. Another alternative would be MallocT<> as follows */
-template <typename T> FORCEINLINE bool ReallocT(T** t_ptr, size_t num_elements)
+template <typename T> FORCEINLINE T* ReallocT(T* t_ptr, size_t num_elements)
{
- *t_ptr = (T*)realloc(*t_ptr, num_elements * sizeof(T));
- return (*t_ptr != NULL);
+ t_ptr = (T*)realloc(t_ptr, num_elements * sizeof(T));
+ return t_ptr;
}
/** type safe swap operation */