Automatic GLPK env deallocation (#213)
authorBalazs Dezso <deba@inf.elte.hu>
Mon, 23 Feb 2009 23:44:29 +0100
changeset 526ba124394367a
parent 525 0fec6a017ead
child 530 fc6c7aab4b8d
Automatic GLPK env deallocation (#213)
lemon/glpk.cc
lemon/glpk.h
test/lp_test.cc
test/mip_test.cc
     1.1 --- a/lemon/glpk.cc	Mon Feb 23 22:54:25 2009 +0100
     1.2 +++ b/lemon/glpk.cc	Mon Feb 23 23:44:29 2009 +0100
     1.3 @@ -526,6 +526,8 @@
     1.4      glp_free_env();
     1.5    }
     1.6  
     1.7 +  GlpkBase::FreeEnvHelper GlpkBase::freeEnvHelper;
     1.8 +
     1.9    // GlpkLp members
    1.10  
    1.11    GlpkLp::GlpkLp()
     2.1 --- a/lemon/glpk.h	Mon Feb 23 22:54:25 2009 +0100
     2.2 +++ b/lemon/glpk.h	Mon Feb 23 23:44:29 2009 +0100
     2.3 @@ -100,16 +100,20 @@
     2.4  
     2.5      virtual void _clear();
     2.6  
     2.7 +  private:
     2.8 +
     2.9 +    static void freeEnv();
    2.10 +
    2.11 +    struct FreeEnvHelper {
    2.12 +      ~FreeEnvHelper() {
    2.13 +        freeEnv();
    2.14 +      }
    2.15 +    };
    2.16 +    
    2.17 +    static FreeEnvHelper freeEnvHelper;
    2.18 +    
    2.19    public:
    2.20  
    2.21 -    /// \brief Deallocates the globally allocated memory of GLPK.
    2.22 -
    2.23 -    /// Deallocates the globally allocated memory of GLPK.  \note
    2.24 -    /// Usually, it do not have to be called, because the GLPK use
    2.25 -    /// only a small amount of global memory, and it is deallocated
    2.26 -    /// automatically at the end of program.
    2.27 -    static void freeEnv();
    2.28 -
    2.29      ///Pointer to the underlying GLPK data structure.
    2.30      LPX *lpx() {return lp;}
    2.31      ///Const pointer to the underlying GLPK data structure.
     3.1 --- a/test/lp_test.cc	Mon Feb 23 22:54:25 2009 +0100
     3.2 +++ b/test/lp_test.cc	Mon Feb 23 23:44:29 2009 +0100
     3.3 @@ -366,7 +366,6 @@
     3.4      lpTest(lp_glpk1);
     3.5      aTest(lp_glpk2);
     3.6    }
     3.7 -  GlpkLp::freeEnv();
     3.8  #endif
     3.9  
    3.10  #ifdef HAVE_CPLEX
     4.1 --- a/test/mip_test.cc	Mon Feb 23 22:54:25 2009 +0100
     4.2 +++ b/test/mip_test.cc	Mon Feb 23 23:44:29 2009 +0100
     4.3 @@ -115,7 +115,6 @@
     4.4      GlpkMip mip1;
     4.5      aTest(mip1);
     4.6    }
     4.7 -  GlpkLp::freeEnv();
     4.8  #endif
     4.9  
    4.10  #ifdef HAVE_CPLEX