Show
Ignore:
Timestamp:
08/12/09 09:27:40 (15 years ago)
Author:
vbarta
Message:

returning shared pointers from epdf::marginal & epdf::condition; testsuite run leaks down from 8402 to 6510 bytes

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • library/bdm/stat/emix.h

    r503 r504  
    3939        //! Nominator in the form of mpdf 
    4040        const epdf* nom; 
     41 
    4142        //!Denominator in the form of epdf 
    42         epdf* den; 
     43        shared_ptr<epdf> den; 
     44 
    4345        //!flag for destructor 
    4446        bool destroynom; 
     
    8587        //! Default destructor 
    8688        ~mratio() { 
    87                 delete den; 
    8889                if ( destroynom ) { 
    8990                        delete nom; 
     
    107108        vec w; 
    108109        //! Component (epdfs) 
    109         Array<epdf*> Coms; 
    110         //!Flag if owning Coms 
    111         bool destroyComs; 
     110        Array<shared_ptr<epdf> > Coms; 
     111 
    112112public: 
    113113        //!Default constructor 
     
    115115        //! Set weights \c w and components \c Coms 
    116116        //!By default Coms are copied inside. Parameter \c copy can be set to false if Coms live externally. Use method ownComs() if Coms should be destroyed by the destructor. 
    117         void set_parameters ( const vec &w, const Array<epdf*> &Coms, bool copy = false ); 
     117        void set_parameters ( const vec &w, const Array<shared_ptr<epdf> > &Coms ); 
    118118 
    119119        vec sample() const; 
     
    164164        }; 
    165165 
    166         emix* marginal ( const RV &rv ) const; 
    167         mratio* condition ( const RV &rv ) const; //why not mratio!! 
     166        shared_ptr<epdf> marginal ( const RV &rv ) const; 
     167        void marginal ( const RV &rv, emix &target ) const; 
     168        shared_ptr<mpdf> condition ( const RV &rv ) const; 
    168169 
    169170//Access methods 
     
    172173                return w; 
    173174        } 
    174         virtual ~emix() { 
    175                 if ( destroyComs ) { 
    176                         for ( int i = 0; i < Coms.length(); i++ ) { 
    177                                 delete Coms ( i ); 
    178                         } 
    179                 } 
    180         } 
    181         //! Auxiliary function for taking ownership of the Coms() 
    182         void ownComs() { 
    183                 destroyComs = true; 
    184         } 
    185175 
    186176        //!access function 
    187         epdf* _Coms ( int i ) { 
     177        shared_ptr<epdf> _Coms ( int i ) { 
    188178                return Coms ( i ); 
    189179        } 
     180 
    190181        void set_rv ( const RV &rv ) { 
    191182                epdf::set_rv ( rv ); 
     
    233224        double lognc () const { 
    234225                return 0; 
    235         }; 
    236         emix* marginal ( const RV &rv ) const; 
     226        } 
     227 
     228        shared_ptr<epdf> marginal ( const RV &rv ) const; 
     229        void marginal ( const RV &rv, emix &target ) const; 
    237230 
    238231//Access methods