-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not extend the pool on each allocation
Reported in Boost mailing list: https://lists.boost.org/Archives/boost/2023/06/254750.php Commit 951ca57 changed malloc_need_resize() to use set_next_size(), which sets start_size in addition to setting next_size. this causes repeated use of purge_memory() to allocate 2x size after every use. Fixes #54
- Loading branch information
Showing
3 changed files
with
42 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* Copyright (C) 2023 Orgad Shaneh | ||
* | ||
* Use, modification and distribution is subject to the | ||
* Boost Software License, Version 1.0. (See accompanying | ||
* file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) | ||
*/ | ||
|
||
// Test of bug #54 (https://github.com/boostorg/pool/issues/54) | ||
|
||
#include <boost/pool/pool.hpp> | ||
#include <boost/limits.hpp> | ||
|
||
int main() | ||
{ | ||
boost::pool<> pool(8, 32, 64); | ||
// On 32 next_size reaches max_size. | ||
// One more round to asserts that it remains 64 (max_size) | ||
for (int i = 0; i <= 33; ++i) { | ||
size_t expected = (i == 0) ? 32 : 64; | ||
BOOST_ASSERT(pool.get_next_size() == expected); | ||
void *ptr = pool.malloc(); | ||
BOOST_ASSERT(ptr); | ||
} | ||
|
||
return 0; | ||
} |