|
Boost : |
Subject: Re: [boost] different matrix library?
From: DE (satan66613_at_[hidden])
Date: 2009-08-18 13:57:38
on 18.08.2009 at 21:33
joel wrote :
> 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 ;
> }
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
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk