Boost logo

Boost Users :

Subject: Re: [Boost-users] Mersenne twister problem
From: ruya (rmlopes_at_[hidden])
Date: 2009-09-16 04:38:09


SType is not a SearchFunctor. It is a template parameter of SearchFunctor.
Look, I am not a professional coder or something. I could accept that my
code has memory leaks, except that I monitored the memory usage and it is
stable and quite small too. I have three other algorithms using the same
SearchFunctors and the behavior is as expected and no memory leaks.
As for the complication that my code appears to be to you, how would you
simplify it? You argued before that you would do it diferently and avoid for
sure the segmentation fault.

Rui

Matthias Troyer-2 wrote:
>
>
> On Sep 15, 2009, at 10:50 AM, ruya wrote:
>
>>
>> SearchFunctor has a virtual destructor, the derivees have empty
>> destructor.
>> MemHandler is just a helper does not store anything.
>
> Here is my guess as to what happens: SPtr points to a SearchFunctor
> that has been deallocated. The generators were never deleted and can
> still be used, but the underlying engine got destroyed. Your code
> contains memory leaks, and could be simplified a lot.
>
> Matthias
>
>
>>
>> template< class SType, typename MemP >
>> class SearchFunctor{
>> protected:
>> typedef SmartPtr<SType> SPtr;
>> typedef typename SType::Domain Domain;
>> typedef typename SType::DPtr DPtr;
>> typedef typename Domain::MType MType;
>> typedef typename Domain::MPtr MPtr;
>> typedef typename Domain::EPtr EPtr;
>> typedef typename Domain::RPtr RPtr;
>> typedef vector<typename SType::MPtr> MVector;
>> typedef typename SType::DataType DataType;
>> typedef boost::mt19937 base_generator_type;
>> typedef boost::variate_generator<base_generator_type&,
>> boost::uniform_real<> > GeneratorI;
>> typedef Private<MemP::ObjectType::_ACTIVE,MemP> MemHandler;
>> public:
>>
>> virtual SPtr operator()( SPtr s, int iter ) = 0;
>>
>> SearchFunctor(){
>> memh = MemHandler();
>> generator1 = base_generator_type(MASTER_SEED+13);
>> uni_dist1 = boost::uniform_real<>(0,1);
>> uniEmp = new GeneratorI(generator1, uni_dist1);
>> generator2 = base_generator_type(MASTER_SEED+17);
>> uni_dist2 = boost::uniform_real<>(0,1);
>> uniRes = new GeneratorI(generator2, uni_dist2);
>> }
>> protected:
>> virtual ~SearchFunctor(){}
>>
>> base_generator_type generator1, generator2;
>> boost::uniform_real<> uni_dist1, uni_dist2;
>> GeneratorI* uniEmp;
>> GeneratorI* uniRes;
>> MemHandler memh;
>> };
>>
>>
>>
>> Matthias Troyer-2 wrote:
>>>
>>>
>>> On Sep 14, 2009, at 9:40 AM, ruya wrote:
>>>
>>>>
>>>> Hi
>>>>
>>>>
>>>> Matthias Troyer-2 wrote:
>>>>>
>>>>> I would write this very differently, and can give you a better
>>>>> version
>>>>> that should have no problems, but could you please send me the
>>>>> definition of GeneratorI first?
>>>>>
>>>> Sorry about that, the missing typedefs at SearchFunctor:
>>>>
>>>> typedef boost::mt19937 base_generator_type;
>>>> typedef boost::variate_generator<base_generator_type&,
>>>> boost::uniform_real<> > GeneratorI;
>>>
>>>
>>> Another question: what does the destructor of your class look like?
>>> Can you send the full class?
>>>
>>> Matthias
>>>
>>> _______________________________________________
>>> Boost-users mailing list
>>> Boost-users_at_[hidden]
>>> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>>>
>>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Mersenne-twister-problem-tp25382114p25450374.html
>> Sent from the Boost - Users mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> Boost-users mailing list
>> Boost-users_at_[hidden]
>> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
>

-- 
View this message in context: http://www.nabble.com/Mersenne-twister-problem-tp25382114p25468208.html
Sent from the Boost - Users mailing list archive at Nabble.com.

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net