mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-28 06:22:14 +03:00
88e90957a1
This is one of those little chores in managing a long-lived C++ project: standard C headers like stdio.h and math.h now have their own place in the C++ standard as resp. cstdio, cmath, and so on. In this branch the #include names are updated for the util/ subdirectory; more branches to follow. C++11 adds cstdint, but to support compilation with the previous standard, that change is left for later.
37 lines
693 B
C++
37 lines
693 B
C++
#include "util/pool.hh"
|
|
|
|
#include "util/scoped.hh"
|
|
|
|
#include <cstdlib>
|
|
|
|
namespace util {
|
|
|
|
Pool::Pool() {
|
|
current_ = NULL;
|
|
current_end_ = NULL;
|
|
}
|
|
|
|
Pool::~Pool() {
|
|
FreeAll();
|
|
}
|
|
|
|
void Pool::FreeAll() {
|
|
for (std::vector<void *>::const_iterator i(free_list_.begin()); i != free_list_.end(); ++i) {
|
|
free(*i);
|
|
}
|
|
free_list_.clear();
|
|
current_ = NULL;
|
|
current_end_ = NULL;
|
|
}
|
|
|
|
void *Pool::More(std::size_t size) {
|
|
std::size_t amount = std::max(static_cast<size_t>(32) << free_list_.size(), size);
|
|
uint8_t *ret = static_cast<uint8_t*>(MallocOrThrow(amount));
|
|
free_list_.push_back(ret);
|
|
current_ = ret + size;
|
|
current_end_ = ret + amount;
|
|
return ret;
|
|
}
|
|
|
|
} // namespace util
|