}
else
{
- // TODO round to preferred granularity ?
+ // Round to preferred granularity.
+ if (opts.max_blocks_per_chunk < size_t(-4))
+ {
+ // round up
+ opts.max_blocks_per_chunk
+ = aligned_ceil(opts.max_blocks_per_chunk, 4);
+ }
+ else
+ {
+ // round down
+ opts.max_blocks_per_chunk &= ~size_t(3);
+ }
}
if (opts.max_blocks_per_chunk > chunk::max_blocks_per_chunk())
: pool_sizes[i];
// Decide on initial number of blocks per chunk.
- // Always have at least 16 blocks per chunk:
- const size_t min_blocks_per_chunk = 16;
- // But for smaller blocks, use a larger initial size:
- size_t blocks_per_chunk
- = std::max(1024 / block_size, min_blocks_per_chunk);
+ // At least 16 blocks per chunk seems reasonable,
+ // more for smaller blocks:
+ size_t blocks_per_chunk = std::max(size_t(16), 1024 / block_size);
// But don't exceed the requested max_blocks_per_chunk:
blocks_per_chunk
= std::min(blocks_per_chunk, _M_opts.max_blocks_per_chunk);
}
}
+void
+test08()
+{
+ std::pmr::pool_options opts;
+ opts.largest_required_pool_block = 64;
+
+ // PR libstdc++/94160
+ // max_blocks_per_chunk=1 causes pool resources to return null pointers
+ for (int i = 0; i < 8; ++i)
+ {
+ opts.max_blocks_per_chunk = i;
+ std::pmr::unsynchronized_pool_resource upr(opts);
+ auto* p = (int*)upr.allocate(4);
+ VERIFY( p != nullptr );
+ *p = i;
+ upr.deallocate(p, 4);
+ }
+}
+
int
main()
{
test05();
test06();
test07();
+ test08();
}