(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
This commit is contained in:
@@ -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 */
|
||||
|
Reference in New Issue
Block a user