From 7f84462785317629d2c5c946f340ad4d0e4d5e5b Mon Sep 17 00:00:00 2001 From: Hieu Hoang Date: Wed, 26 Oct 2016 16:50:20 +0100 Subject: Separate MemPoolAllocator from MemPool --- contrib/moses2/HypothesisColl.cpp | 1 + contrib/moses2/HypothesisColl.h | 2 +- contrib/moses2/Main.cpp | 2 +- contrib/moses2/MemPool.h | 79 ------------------- contrib/moses2/MemPoolAllocator.h | 90 ++++++++++++++++++++++ .../moses2/PhraseBased/CubePruningMiniStack/Misc.h | 1 + .../PhraseBased/CubePruningMiniStack/Search.h | 1 + .../PhraseBased/CubePruningMiniStack/Stack.h | 1 + contrib/moses2/SCFG/InputPath.cpp | 2 +- contrib/moses2/SCFG/InputPath.h | 1 + contrib/moses2/Vector.h | 2 +- 11 files changed, 99 insertions(+), 83 deletions(-) create mode 100644 contrib/moses2/MemPoolAllocator.h diff --git a/contrib/moses2/HypothesisColl.cpp b/contrib/moses2/HypothesisColl.cpp index b101acdf8..2af5465e3 100644 --- a/contrib/moses2/HypothesisColl.cpp +++ b/contrib/moses2/HypothesisColl.cpp @@ -11,6 +11,7 @@ #include "HypothesisColl.h" #include "ManagerBase.h" #include "System.h" +#include "MemPoolAllocator.h" using namespace std; diff --git a/contrib/moses2/HypothesisColl.h b/contrib/moses2/HypothesisColl.h index 363f52a59..cea3bee1b 100644 --- a/contrib/moses2/HypothesisColl.h +++ b/contrib/moses2/HypothesisColl.h @@ -7,7 +7,7 @@ #pragma once #include #include "HypothesisBase.h" -#include "MemPool.h" +#include "MemPoolAllocator.h" #include "Recycler.h" #include "Array.h" #include "legacy/Util2.h" diff --git a/contrib/moses2/Main.cpp b/contrib/moses2/Main.cpp index 8bf1ce86b..0661d1d0e 100644 --- a/contrib/moses2/Main.cpp +++ b/contrib/moses2/Main.cpp @@ -5,7 +5,7 @@ #include "System.h" #include "Phrase.h" #include "TranslationTask.h" -#include "MemPool.h" +#include "MemPoolAllocator.h" #include "server/Server.h" #include "legacy/InputFileStream.h" #include "legacy/Parameter.h" diff --git a/contrib/moses2/MemPool.h b/contrib/moses2/MemPool.h index cca803775..eaa55915e 100644 --- a/contrib/moses2/MemPool.h +++ b/contrib/moses2/MemPool.h @@ -169,86 +169,7 @@ private: }; ////////////////////////////////////////////////////////////////////////////////////////// -template -class MemPoolAllocator -{ -public: - typedef T value_type; - typedef T* pointer; - typedef const T* const_pointer; - typedef T& reference; - typedef const T& const_reference; - typedef std::size_t size_type; - typedef std::ptrdiff_t difference_type; - - template - struct rebind - { - typedef MemPoolAllocator other; - }; - - MemPoolAllocator(Moses2::MemPool &pool) : - m_pool(pool) - { - } - MemPoolAllocator(const MemPoolAllocator &other) : - m_pool(other.m_pool) - { - } - - template - MemPoolAllocator(const MemPoolAllocator& other) : - m_pool(other.m_pool) - { - } - - size_type max_size() const - { - return std::numeric_limits::max(); - } - - void deallocate(pointer p, size_type n) - { - //std::cerr << "deallocate " << p << " " << n << std::endl; - } - - pointer allocate(size_type n, std::allocator::const_pointer hint = 0) - { - //std::cerr << "allocate " << n << " " << hint << std::endl; - pointer ret = m_pool.Allocate(n); - return ret; - } - - void construct(pointer p, const_reference val) - { - //std::cerr << "construct " << p << " " << n << std::endl; - new ((void *) p) T(val); - } - - void destroy(pointer p) - { - //std::cerr << "destroy " << p << " " << n << std::endl; - } - - // return address of values - pointer address (reference value) const { - return &value; - } - const_pointer address (const_reference value) const { - return &value; - } - bool operator==(const MemPoolAllocator &allocator) const { - return true; - } - - bool operator!=(const MemPoolAllocator &allocator) const { - return false; - } - - MemPool &m_pool; -protected: -}; } diff --git a/contrib/moses2/MemPoolAllocator.h b/contrib/moses2/MemPoolAllocator.h new file mode 100644 index 000000000..6cc699893 --- /dev/null +++ b/contrib/moses2/MemPoolAllocator.h @@ -0,0 +1,90 @@ +#pragma once +#include "MemPool.h" + +namespace Moses2 +{ + +template +class MemPoolAllocator +{ +public: + typedef T value_type; + typedef T* pointer; + typedef const T* const_pointer; + typedef T& reference; + typedef const T& const_reference; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; + + template + struct rebind + { + typedef MemPoolAllocator other; + }; + + MemPoolAllocator(Moses2::MemPool &pool) : + m_pool(pool) + { + } + MemPoolAllocator(const MemPoolAllocator &other) : + m_pool(other.m_pool) + { + } + + template + MemPoolAllocator(const MemPoolAllocator& other) : + m_pool(other.m_pool) + { + } + + size_type max_size() const + { + return std::numeric_limits::max(); + } + + void deallocate(pointer p, size_type n) + { + //std::cerr << "deallocate " << p << " " << n << std::endl; + } + + pointer allocate(size_type n, std::allocator::const_pointer hint = 0) + { + //std::cerr << "allocate " << n << " " << hint << std::endl; + pointer ret = m_pool.Allocate(n); + return ret; + } + + void construct(pointer p, const_reference val) + { + //std::cerr << "construct " << p << " " << n << std::endl; + new ((void *) p) T(val); + } + + void destroy(pointer p) + { + //std::cerr << "destroy " << p << " " << n << std::endl; + } + + // return address of values + pointer address (reference value) const { + return &value; + } + const_pointer address (const_reference value) const { + return &value; + } + + bool operator==(const MemPoolAllocator &allocator) const { + return true; + } + + bool operator!=(const MemPoolAllocator &allocator) const { + return false; + } + + MemPool &m_pool; +protected: +}; + +} + + diff --git a/contrib/moses2/PhraseBased/CubePruningMiniStack/Misc.h b/contrib/moses2/PhraseBased/CubePruningMiniStack/Misc.h index f6e396f13..535ef6ada 100644 --- a/contrib/moses2/PhraseBased/CubePruningMiniStack/Misc.h +++ b/contrib/moses2/PhraseBased/CubePruningMiniStack/Misc.h @@ -14,6 +14,7 @@ #include "../Hypothesis.h" #include "../../TypeDef.h" #include "../../Vector.h" +#include "../../MemPoolAllocator.h" #include "Stack.h" namespace Moses2 diff --git a/contrib/moses2/PhraseBased/CubePruningMiniStack/Search.h b/contrib/moses2/PhraseBased/CubePruningMiniStack/Search.h index 65fc82c8e..0dfe9dfb2 100644 --- a/contrib/moses2/PhraseBased/CubePruningMiniStack/Search.h +++ b/contrib/moses2/PhraseBased/CubePruningMiniStack/Search.h @@ -11,6 +11,7 @@ #include "Misc.h" #include "Stack.h" #include "../../legacy/Range.h" +#include "../../MemPoolAllocator.h" namespace Moses2 { diff --git a/contrib/moses2/PhraseBased/CubePruningMiniStack/Stack.h b/contrib/moses2/PhraseBased/CubePruningMiniStack/Stack.h index ed7025d1b..7601f90b2 100644 --- a/contrib/moses2/PhraseBased/CubePruningMiniStack/Stack.h +++ b/contrib/moses2/PhraseBased/CubePruningMiniStack/Stack.h @@ -12,6 +12,7 @@ #include "../../TypeDef.h" #include "../../Vector.h" #include "../../MemPool.h" +#include "../../MemPoolAllocator.h" #include "../../Recycler.h" #include "../../HypothesisColl.h" #include "../../legacy/Util2.h" diff --git a/contrib/moses2/SCFG/InputPath.cpp b/contrib/moses2/SCFG/InputPath.cpp index f0c34bbc6..1ebbbf327 100644 --- a/contrib/moses2/SCFG/InputPath.cpp +++ b/contrib/moses2/SCFG/InputPath.cpp @@ -9,7 +9,7 @@ #include "TargetPhrases.h" #include "ActiveChart.h" #include "../TranslationModel/PhraseTable.h" -#include "../MemPool.h" +#include "../MemPoolAllocator.h" using namespace std; diff --git a/contrib/moses2/SCFG/InputPath.h b/contrib/moses2/SCFG/InputPath.h index e135276ff..c8a7253c2 100644 --- a/contrib/moses2/SCFG/InputPath.h +++ b/contrib/moses2/SCFG/InputPath.h @@ -11,6 +11,7 @@ #include #include #include "../InputPathBase.h" +#include "../MemPoolAllocator.h" #include "TargetPhrases.h" #include "ActiveChart.h" #include "Word.h" diff --git a/contrib/moses2/Vector.h b/contrib/moses2/Vector.h index 7c7a172fd..f35e71825 100644 --- a/contrib/moses2/Vector.h +++ b/contrib/moses2/Vector.h @@ -7,7 +7,7 @@ #pragma once #include -#include "MemPool.h" +#include "MemPoolAllocator.h" namespace Moses2 { -- cgit v1.2.3