mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-10-05 15:58:03 +03:00
align memory to 16 bytes. Move Allocate() to cpp
This commit is contained in:
parent
a93c3270dc
commit
daf35ead47
@ -98,8 +98,8 @@ void batch_run(Moses2::Parameter& params, Moses2::System& system, Moses2::Thread
|
||||
boost::shared_ptr<Moses2::TranslationTask> task(new Moses2::TranslationTask(system, line, translationId));
|
||||
|
||||
//cerr << "START pool.Submit()" << endl;
|
||||
pool.Submit(task);
|
||||
//task->Run();
|
||||
//pool.Submit(task);
|
||||
task->Run();
|
||||
++translationId;
|
||||
}
|
||||
|
||||
|
@ -43,6 +43,29 @@ MemPool::~MemPool()
|
||||
RemoveAllInColl(m_pages);
|
||||
}
|
||||
|
||||
uint8_t* MemPool::Allocate(std::size_t size) {
|
||||
if (size == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
//size = (size + 3) & 0xfffffffc;
|
||||
//size = (size + 7) & 0xfffffff8;
|
||||
size = (size + 15) & 0xfffffff0;
|
||||
//size = (size + 31) & 0xffffffe0;
|
||||
|
||||
uint8_t* ret = current_;
|
||||
current_ += size;
|
||||
|
||||
Page& page = *m_pages[m_currPage];
|
||||
if (current_ <= page.end) {
|
||||
// return what we got
|
||||
}
|
||||
else {
|
||||
ret = More(size);
|
||||
}
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
uint8_t *MemPool::More(std::size_t size)
|
||||
{
|
||||
++m_currPage;
|
||||
|
19
moses2/MemPool.h
Normal file → Executable file
19
moses2/MemPool.h
Normal file → Executable file
@ -25,8 +25,7 @@ class MemPool
|
||||
uint8_t *end;
|
||||
size_t size;
|
||||
|
||||
Page() {
|
||||
}
|
||||
Page() = delete;
|
||||
Page(std::size_t size);
|
||||
~Page();
|
||||
};
|
||||
@ -36,21 +35,7 @@ public:
|
||||
|
||||
~MemPool();
|
||||
|
||||
uint8_t *Allocate(std::size_t size) {
|
||||
size = (size + 3) & 0xfffffffc;
|
||||
|
||||
uint8_t *ret = current_;
|
||||
current_ += size;
|
||||
|
||||
Page &page = *m_pages[m_currPage];
|
||||
if (current_ <= page.end) {
|
||||
// return what we got
|
||||
} else {
|
||||
ret = More(size);
|
||||
}
|
||||
return ret;
|
||||
|
||||
}
|
||||
uint8_t* Allocate(std::size_t size);
|
||||
|
||||
template<typename T>
|
||||
T *Allocate() {
|
||||
|
Loading…
Reference in New Issue
Block a user