mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-30 23:42:30 +03:00
stem leak by using mempool
This commit is contained in:
parent
dfabbda5aa
commit
259cb96538
@ -19,27 +19,30 @@ namespace Moses2
|
||||
|
||||
namespace SCFG
|
||||
{
|
||||
TrellisNode::TrellisNode(const ArcLists &arcLists, const SCFG::Hypothesis &hypo)
|
||||
TrellisNode::TrellisNode(MemPool &pool, const ArcLists &arcLists, const SCFG::Hypothesis &hypo)
|
||||
:arcList(arcLists.GetArcList(&hypo))
|
||||
,ind(0)
|
||||
,m_prevNodes(pool)
|
||||
{
|
||||
UTIL_THROW_IF2(arcList.size() == 0, "Empty arclist");
|
||||
ind = 0;
|
||||
|
||||
CreateTail(arcLists, hypo);
|
||||
CreateTail(pool, arcLists, hypo);
|
||||
}
|
||||
|
||||
TrellisNode::TrellisNode(const ArcLists &arcLists, const ArcList &varcList, size_t vind)
|
||||
TrellisNode::TrellisNode(MemPool &pool, const ArcLists &arcLists, const ArcList &varcList, size_t vind)
|
||||
:arcList(varcList)
|
||||
,ind(vind)
|
||||
,ind(vind)
|
||||
,m_prevNodes(pool)
|
||||
{
|
||||
UTIL_THROW_IF2(vind >= arcList.size(), "arclist out of bound" << ind << " >= " << arcList.size());
|
||||
const SCFG::Hypothesis &hypo = arcList[ind]->Cast<SCFG::Hypothesis>();
|
||||
CreateTail(arcLists, hypo);
|
||||
CreateTail(pool, arcLists, hypo);
|
||||
}
|
||||
|
||||
TrellisNode::TrellisNode(const ArcLists &arcLists, const TrellisNode &orig, const TrellisNode &nodeToChange)
|
||||
TrellisNode::TrellisNode(MemPool &pool, const ArcLists &arcLists, const TrellisNode &orig, const TrellisNode &nodeToChange)
|
||||
:arcList(orig.arcList)
|
||||
,ind(orig.ind)
|
||||
,ind(orig.ind)
|
||||
,m_prevNodes(pool)
|
||||
{
|
||||
const TrellisNode::Children &origChildren = orig.GetChildren();
|
||||
m_prevNodes.resize(origChildren.size());
|
||||
@ -49,25 +52,25 @@ TrellisNode::TrellisNode(const ArcLists &arcLists, const TrellisNode &orig, cons
|
||||
const TrellisNode *origChild = origChildren[i];
|
||||
if (origChild != &nodeToChange) {
|
||||
// recurse
|
||||
newChild = new TrellisNode(arcLists, *origChild, nodeToChange);
|
||||
newChild = new (pool.Allocate<TrellisNode>()) TrellisNode(pool, arcLists, *origChild, nodeToChange);
|
||||
}
|
||||
else {
|
||||
size_t nextInd = nodeToChange.ind + 1;
|
||||
newChild = new TrellisNode(arcLists, nodeToChange.arcList, nextInd);
|
||||
newChild = new (pool.Allocate<TrellisNode>()) TrellisNode(pool, arcLists, nodeToChange.arcList, nextInd);
|
||||
}
|
||||
|
||||
m_prevNodes[i] = newChild;
|
||||
}
|
||||
}
|
||||
|
||||
void TrellisNode::CreateTail(const ArcLists &arcLists, const SCFG::Hypothesis &hypo)
|
||||
void TrellisNode::CreateTail(MemPool &pool, const ArcLists &arcLists, const SCFG::Hypothesis &hypo)
|
||||
{
|
||||
const Vector<const Hypothesis*> &prevHypos = hypo.GetPrevHypos();
|
||||
m_prevNodes.resize(prevHypos.size(), NULL);
|
||||
|
||||
for (size_t i = 0; i < hypo.GetPrevHypos().size(); ++i) {
|
||||
const SCFG::Hypothesis &prevHypo = *prevHypos[i];
|
||||
TrellisNode *prevNode = new TrellisNode(arcLists, prevHypo);
|
||||
TrellisNode *prevNode = new (pool.Allocate<TrellisNode>()) TrellisNode(pool, arcLists, prevHypo);
|
||||
m_prevNodes[i] = prevNode;
|
||||
}
|
||||
}
|
||||
@ -119,7 +122,7 @@ TrellisPath::TrellisPath(const SCFG::Manager &mgr, const SCFG::Hypothesis &hypo)
|
||||
// 1st
|
||||
m_scores = m_scores = new (pool.Allocate<Scores>())
|
||||
Scores(mgr.system, pool, mgr.system.featureFunctions.GetNumScores(), hypo.GetScores());
|
||||
m_node = new TrellisNode(mgr.arcLists, hypo);
|
||||
m_node = new (pool.Allocate<TrellisNode>()) TrellisNode(pool, mgr.arcLists, hypo);
|
||||
m_prevNodeChanged = m_node;
|
||||
}
|
||||
|
||||
@ -139,13 +142,13 @@ TrellisPath::TrellisPath(const SCFG::Manager &mgr, const SCFG::TrellisPath &orig
|
||||
m_scores->PlusEquals(mgr.system, nextHypo.GetScores());
|
||||
|
||||
if (origPath.m_node == &nodeToChange) {
|
||||
m_node = new TrellisNode(mgr.arcLists, nodeToChange.arcList, nodeToChange.ind + 1);
|
||||
m_node = new (pool.Allocate<TrellisNode>()) TrellisNode(pool, mgr.arcLists, nodeToChange.arcList, nodeToChange.ind + 1);
|
||||
m_prevNodeChanged= m_node;
|
||||
}
|
||||
else {
|
||||
// recursively copy nodes until we find the node that needs to change
|
||||
m_node = new TrellisNode(mgr.arcLists, *origPath.m_node, nodeToChange);
|
||||
m_prevNodeChanged= m_node;
|
||||
// recursively copy nodes until we find the node that needs to change
|
||||
m_node = new (pool.Allocate<TrellisNode>()) TrellisNode(pool, mgr.arcLists, *origPath.m_node, nodeToChange);
|
||||
m_prevNodeChanged= m_node;
|
||||
}
|
||||
}
|
||||
|
||||
@ -169,8 +172,10 @@ SCORE TrellisPath::GetFutureScore() const
|
||||
void TrellisPath::CreateDeviantPaths(TrellisPaths<SCFG::TrellisPath> &paths, const SCFG::Manager &mgr) const
|
||||
{
|
||||
if (m_prevNodeChanged->HasMore()) {
|
||||
MemPool &pool = mgr.GetPool();
|
||||
|
||||
//cerr << "BEGIN deviantPath" << endl;
|
||||
SCFG::TrellisPath *deviantPath = new TrellisPath(mgr, *this, *m_prevNodeChanged);
|
||||
SCFG::TrellisPath *deviantPath = new SCFG::TrellisPath(mgr, *this, *m_prevNodeChanged);
|
||||
//cerr << "END deviantPath" << endl;
|
||||
paths.Add(deviantPath);
|
||||
//cerr << "ADDED deviantPath" << endl;
|
||||
|
@ -7,6 +7,7 @@
|
||||
#pragma once
|
||||
#include "../ArcLists.h"
|
||||
#include "../TypeDef.h"
|
||||
#include "../Vector.h"
|
||||
|
||||
namespace Moses2
|
||||
{
|
||||
@ -25,15 +26,15 @@ class Hypothesis;
|
||||
class TrellisNode
|
||||
{
|
||||
public:
|
||||
typedef std::vector<const TrellisNode*> Children;
|
||||
typedef Vector<const TrellisNode*> Children;
|
||||
|
||||
const ArcList &arcList;
|
||||
size_t ind;
|
||||
|
||||
TrellisNode(const ArcLists &arcLists, const SCFG::Hypothesis &hypo);
|
||||
TrellisNode(const ArcLists &arcLists, const ArcList &varcList, size_t vind);
|
||||
TrellisNode(MemPool &pool, const ArcLists &arcLists, const SCFG::Hypothesis &hypo);
|
||||
TrellisNode(MemPool &pool, const ArcLists &arcLists, const ArcList &varcList, size_t vind);
|
||||
|
||||
TrellisNode(const ArcLists &arcLists, const TrellisNode &orig, const TrellisNode &nodeToChange);
|
||||
TrellisNode(MemPool &pool, const ArcLists &arcLists, const TrellisNode &orig, const TrellisNode &nodeToChange);
|
||||
|
||||
const SCFG::Hypothesis &GetHypothesis() const;
|
||||
bool HasMore() const;
|
||||
@ -45,7 +46,7 @@ public:
|
||||
protected:
|
||||
Children m_prevNodes;
|
||||
|
||||
void CreateTail(const ArcLists &arcLists, const SCFG::Hypothesis &hypo);
|
||||
void CreateTail(MemPool &pool, const ArcLists &arcLists, const SCFG::Hypothesis &hypo);
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
Loading…
Reference in New Issue
Block a user