From 15b8c97fced4da2232bd99e5f4e74e3a5e2754b6 Mon Sep 17 00:00:00 2001 From: Hieu Hoang Date: Tue, 7 Jun 2016 17:57:33 +0100 Subject: [PATCH] use mempool to stem leak --- contrib/other-builds/moses2/InputType.cpp | 5 +++++ contrib/other-builds/moses2/InputType.h | 6 +----- contrib/other-builds/moses2/PhraseBased/Sentence.h | 2 +- contrib/other-builds/moses2/ReorderingConstraint.cpp | 9 +++++---- contrib/other-builds/moses2/ReorderingConstraint.h | 5 ++++- contrib/other-builds/moses2/SCFG/Sentence.h | 2 +- 6 files changed, 17 insertions(+), 12 deletions(-) diff --git a/contrib/other-builds/moses2/InputType.cpp b/contrib/other-builds/moses2/InputType.cpp index 6063ada8e..59339d779 100644 --- a/contrib/other-builds/moses2/InputType.cpp +++ b/contrib/other-builds/moses2/InputType.cpp @@ -9,6 +9,11 @@ namespace Moses2 { +InputType::InputType(long translationId, MemPool &pool) +:m_translationId(translationId) +,m_reorderingConstraint(pool) +{ +} InputType::~InputType() { diff --git a/contrib/other-builds/moses2/InputType.h b/contrib/other-builds/moses2/InputType.h index ef0426aa2..6b8e1c721 100644 --- a/contrib/other-builds/moses2/InputType.h +++ b/contrib/other-builds/moses2/InputType.h @@ -15,11 +15,7 @@ namespace Moses2 class InputType { public: - InputType(long translationId) : - m_translationId(translationId) - { - } - + InputType(long translationId, MemPool &pool); virtual ~InputType(); virtual void Init(size_t size, int max_distortion); diff --git a/contrib/other-builds/moses2/PhraseBased/Sentence.h b/contrib/other-builds/moses2/PhraseBased/Sentence.h index ed5e03b50..a2619398c 100644 --- a/contrib/other-builds/moses2/PhraseBased/Sentence.h +++ b/contrib/other-builds/moses2/PhraseBased/Sentence.h @@ -39,7 +39,7 @@ public: const System &system, const std::string &str, long translationId); Sentence(long translationId, MemPool &pool, size_t size) - :InputType(translationId) + :InputType(translationId, pool) ,PhraseImpl(pool, size) {} diff --git a/contrib/other-builds/moses2/ReorderingConstraint.cpp b/contrib/other-builds/moses2/ReorderingConstraint.cpp index 24ff11f41..8e5712ef2 100644 --- a/contrib/other-builds/moses2/ReorderingConstraint.cpp +++ b/contrib/other-builds/moses2/ReorderingConstraint.cpp @@ -12,16 +12,17 @@ namespace Moses2 //! destructer ReorderingConstraint::~ReorderingConstraint() { - if (m_wall != NULL) free(m_wall); - if (m_localWall != NULL) free(m_localWall); + //if (m_wall != NULL) free(m_wall); + //if (m_localWall != NULL) free(m_localWall); } //! allocate memory for reordering walls void ReorderingConstraint::InitializeWalls(size_t size, int max_distortion) { m_size = size; - m_wall = (bool*) malloc(sizeof(bool) * size); - m_localWall = (size_t*) malloc(sizeof(size_t) * size); + + m_wall = m_pool.Allocate(size); + m_localWall = m_pool.Allocate(size); m_max_distortion = max_distortion; diff --git a/contrib/other-builds/moses2/ReorderingConstraint.h b/contrib/other-builds/moses2/ReorderingConstraint.h index 6b9774df2..4e6a59fc8 100644 --- a/contrib/other-builds/moses2/ReorderingConstraint.h +++ b/contrib/other-builds/moses2/ReorderingConstraint.h @@ -6,6 +6,7 @@ namespace Moses2 { class Sentence; class Bitmap; +class MemPool; #define NOT_A_ZONE 999999999 @@ -20,16 +21,18 @@ protected: std::vector< std::vector< size_t > > m_zone; /** zones that limit reordering */ bool m_active; /**< flag indicating, if there are any active constraints */ int m_max_distortion; + MemPool &m_pool; ReorderingConstraint(const ReorderingConstraint &); // do not implement public: //! create ReorderingConstraint of length size and initialise to zero - ReorderingConstraint() + ReorderingConstraint(MemPool &pool) : m_wall(NULL) , m_localWall(NULL) , m_active(false) + , m_pool(pool) {} //! destructer diff --git a/contrib/other-builds/moses2/SCFG/Sentence.h b/contrib/other-builds/moses2/SCFG/Sentence.h index b64a3dc52..7400e53aa 100644 --- a/contrib/other-builds/moses2/SCFG/Sentence.h +++ b/contrib/other-builds/moses2/SCFG/Sentence.h @@ -27,7 +27,7 @@ public: const System &system, const std::string &str, long translationId); Sentence(long translationId, MemPool &pool, size_t size) - :InputType(translationId) + :InputType(translationId, pool) ,PhraseImpl(pool, size) {}