Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/kpu/kenlm.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorKenneth Heafield <github@kheafield.com>2021-12-09 14:05:43 +0300
committerKenneth Heafield <github@kheafield.com>2021-12-09 14:06:38 +0300
commit5cea457db26950a73d638425c183b368c06ed7c6 (patch)
tree6200c214637e769067e03f06e61844080785b12e /util
parentf01e12d83c7fd03ebe6656e0ad6d73a3e022bd50 (diff)
Enforce minimum size in FreePool
Diffstat (limited to 'util')
-rw-r--r--util/pool.hh7
1 files changed, 5 insertions, 2 deletions
diff --git a/util/pool.hh b/util/pool.hh
index d72400b..b3cd9e5 100644
--- a/util/pool.hh
+++ b/util/pool.hh
@@ -87,7 +87,9 @@ class Pool {
class FreePool {
public:
explicit FreePool(std::size_t element_size)
- : free_list_(NULL), element_size_(element_size) {}
+ : free_list_(NULL),
+ element_size_(element_size),
+ padded_size_(std::max(element_size_, sizeof(void*))) {}
void *Allocate() {
if (free_list_) {
@@ -95,7 +97,7 @@ class FreePool {
free_list_ = *reinterpret_cast<void**>(free_list_);
return ret;
} else {
- return backing_.Allocate(element_size_);
+ return backing_.Allocate(padded_size_);
}
}
@@ -112,6 +114,7 @@ class FreePool {
Pool backing_;
const std::size_t element_size_;
+ const std::size_t padded_size_;
};
} // namespace util