diff options
author | Kenneth Heafield <github@kheafield.com> | 2012-10-16 20:35:27 +0400 |
---|---|---|
committer | Kenneth Heafield <github@kheafield.com> | 2012-10-16 20:35:27 +0400 |
commit | 96bc9d05dc713e1da29c9bacd6c59f9301fd9981 (patch) | |
tree | 62047871efa45f0083b18b67a03df970df1ab88d /search | |
parent | f9f5b4eb0a6d3b87d8eb98471b532377534644df (diff) |
Move pool to util
Diffstat (limited to 'search')
-rw-r--r-- | search/Jamfile | 2 | ||||
-rw-r--r-- | search/edge.hh | 4 | ||||
-rw-r--r-- | search/pool.cc | 35 | ||||
-rw-r--r-- | search/pool.hh | 43 |
4 files changed, 3 insertions, 81 deletions
diff --git a/search/Jamfile b/search/Jamfile index dcf55558c..bc95c53af 100644 --- a/search/Jamfile +++ b/search/Jamfile @@ -1,4 +1,4 @@ -lib search : weights.cc vertex.cc vertex_generator.cc pool.cc edge_generator.cc rule.cc ../lm//kenlm ../util//kenutil /top//boost_system : : : <include>.. ; +lib search : weights.cc vertex.cc vertex_generator.cc edge_generator.cc rule.cc ../lm//kenlm ../util//kenutil /top//boost_system : : : <include>.. ; import testing ; diff --git a/search/edge.hh b/search/edge.hh index 98085c416..2cdc05f37 100644 --- a/search/edge.hh +++ b/search/edge.hh @@ -2,9 +2,9 @@ #define SEARCH_EDGE__ #include "lm/state.hh" -#include "search/pool.hh" #include "search/types.hh" #include "search/vertex.hh" +#include "util/pool.hh" #include <functional> @@ -69,7 +69,7 @@ class PartialEdgePool { } private: - Pool pool_; + util::Pool pool_; }; diff --git a/search/pool.cc b/search/pool.cc deleted file mode 100644 index 13ec867cf..000000000 --- a/search/pool.cc +++ /dev/null @@ -1,35 +0,0 @@ -#include "search/pool.hh" - -#include <stdlib.h> - -namespace search { - -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*>(malloc(amount)); - if (!ret) throw std::bad_alloc(); - free_list_.push_back(ret); - current_ = ret + size; - current_end_ = ret + amount; - return ret; -} - -} // namespace search diff --git a/search/pool.hh b/search/pool.hh deleted file mode 100644 index d8a1cdd6b..000000000 --- a/search/pool.hh +++ /dev/null @@ -1,43 +0,0 @@ -// Very simple pool. It can only allocate memory. And all of the memory it -// allocates must be freed at the same time. - -#ifndef SEARCH_POOL__ -#define SEARCH_POOL__ - -#include <boost/noncopyable.hpp> - -#include <vector> - -#include <stdint.h> - -namespace search { - -class Pool : boost::noncopyable { - public: - Pool(); - - ~Pool(); - - void *Allocate(size_t size) { - void *ret = current_; - current_ += size; - if (current_ < current_end_) { - return ret; - } else { - return More(size); - } - } - - void FreeAll(); - - private: - void *More(size_t size); - - std::vector<void *> free_list_; - - uint8_t *current_, *current_end_; -}; - -} // namespace lm - -#endif // SEARCH_POOL__ |