Skip to content

Commit

Permalink
Enforce minimum size in FreePool
Browse files Browse the repository at this point in the history
  • Loading branch information
kpu committed Dec 9, 2021
1 parent f01e12d commit 5cea457
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions util/pool.hh
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,17 @@ 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_) {
void *ret = free_list_;
free_list_ = *reinterpret_cast<void**>(free_list_);
return ret;
} else {
return backing_.Allocate(element_size_);
return backing_.Allocate(padded_size_);
}
}

Expand All @@ -112,6 +114,7 @@ class FreePool {
Pool backing_;

const std::size_t element_size_;
const std::size_t padded_size_;
};

} // namespace util
Expand Down

0 comments on commit 5cea457

Please sign in to comment.