use mempool to stem leak

This commit is contained in:
Hieu Hoang 2016-06-07 17:57:33 +01:00
parent 849b161bf8
commit 15b8c97fce
6 changed files with 17 additions and 12 deletions

View File

@ -9,6 +9,11 @@
namespace Moses2
{
InputType::InputType(long translationId, MemPool &pool)
:m_translationId(translationId)
,m_reorderingConstraint(pool)
{
}
InputType::~InputType()
{

View File

@ -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);

View File

@ -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)
{}

View File

@ -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<bool>(size);
m_localWall = m_pool.Allocate<size_t>(size);
m_max_distortion = max_distortion;

View File

@ -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

View File

@ -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)
{}