Use delete[] to deallocate after new[] (#1107)

* Use delete[] to deallocate after new[]

* Fixup formatting with git-clang-format
This commit is contained in:
James Price
2021-01-19 11:35:30 -05:00
committed by GitHub
parent 0d74b3f926
commit af6d55d68c

View File

@@ -69,31 +69,28 @@ C_host_memory_block<T>::C_host_memory_block()
template < class T> template < class T>
C_host_memory_block<T>::~C_host_memory_block() C_host_memory_block<T>::~C_host_memory_block()
{ {
if (pData!=NULL) delete pData; if (pData != NULL) delete[] pData;
num_elements = 0; num_elements = 0;
} }
template < class T > template < class T >
void C_host_memory_block<T>::Init(int num_elem, T & value) void C_host_memory_block<T>::Init(int num_elem, T & value)
{ {
if (pData!=NULL) delete pData; if (pData != NULL) delete[] pData;
pData= new T [num_elem]; pData = new T[num_elem];
for (int i=0; i<num_elem; i++) for (int i = 0; i < num_elem; i++) pData[i] = value;
pData[i] = value;
num_elements= num_elem; num_elements = num_elem;
} }
template < class T > template < class T >
void C_host_memory_block<T>::Init(int num_elem) void C_host_memory_block<T>::Init(int num_elem)
{ {
if (pData!=NULL) delete pData; if (pData != NULL) delete[] pData;
pData = new T [num_elem]; pData = new T[num_elem];
for (int i=0; i<num_elem; i++) for (int i = 0; i < num_elem; i++) pData[i] = (T)i;
pData[i]= (T) i;
num_elements = num_elem;
num_elements = num_elem;
} }
template < class T > template < class T >
void C_host_memory_block<T>::Set_to_zero() void C_host_memory_block<T>::Set_to_zero()