align memory to 16 bytes. Move Allocate() to cpp

This commit is contained in:
Hieu Hoang 2024-02-15 14:59:52 -08:00
parent a93c3270dc
commit daf35ead47
3 changed files with 27 additions and 19 deletions

View File

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

View File

@ -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
View 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() {