mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-27 05:55:02 +03:00
46 lines
747 B
C++
46 lines
747 B
C++
// Very simple pool. It can only allocate memory. And all of the memory it
|
|
// allocates must be freed at the same time.
|
|
|
|
#ifndef UTIL_POOL__
|
|
#define UTIL_POOL__
|
|
|
|
#include <vector>
|
|
|
|
#include <stdint.h>
|
|
|
|
namespace util {
|
|
|
|
class Pool {
|
|
public:
|
|
Pool();
|
|
|
|
~Pool();
|
|
|
|
void *Allocate(std::size_t size) {
|
|
void *ret = current_;
|
|
current_ += size;
|
|
if (current_ < current_end_) {
|
|
return ret;
|
|
} else {
|
|
return More(size);
|
|
}
|
|
}
|
|
|
|
void FreeAll();
|
|
|
|
private:
|
|
void *More(std::size_t size);
|
|
|
|
std::vector<void *> free_list_;
|
|
|
|
uint8_t *current_, *current_end_;
|
|
|
|
// no copying
|
|
Pool(const Pool &);
|
|
Pool &operator=(const Pool &);
|
|
};
|
|
|
|
} // namespace util
|
|
|
|
#endif // UTIL_POOL__
|