
18 Aug
2009
18 Aug
'09
5:57 p.m.
template <typename T> T** alloc_array(int h, int w) { typedef T* ptr_type ; typedef ptr_type* return_type ;
return_type m = new ptr_type[h] ; if (!m) return 0 ; //this is redundant
m[0] = new T[w*h] ; //just to note if new throws 'm' leak if (!m[0]) { delete[] m; return 0 ; }
for (int i=1 ; i < h ; ++i) m[i] = m[i-1] + w ; return m ; }
on 18.08.2009 at 21:33 joel wrote : the redundant line is such because if new fails to allocate memory it throws an exception and control will never reach this line (!m will always be true when checked) the latter i suppose is because of writing on the run -- Pavel