I would like to frequently allocate and reuse buffers of up to multiple hundreds of MBs. I want to use a memory pool for this because I know the target machines possess enough memory capacity and I want to save the time it takes to allocate these buffers with new/malloc/etc.
Then I found the combination of std::pmr::monotonic_buffer_resource and std::pmr::unsynchronized_pool_resource, which creates a memory pool that reuses memory. If it is used with frequent and large allocation sizes, this combination starts to bloat up the memory used by the application. This is because the std::pmr::pool_options.largest_required_pool_block determines if an allocation size will be part of the pool or just directly forwarded to the std::pmr::monotonic_buffer_resource. Since the std::pmr::monotonic_buffer_resource never frees memory until it is destructed, this results in many large allocations that will not be reused. The upper limit of std::pmr::pool_options.largest_required_pool_block is implementation defined, and both clang 19.1.0 and gcc 14.2 set it to 4 MB. As is mentioned above, I would like it to be much higher.
An option I see for solving this is writing my own version of std::pmr::unsynchronized_pool_resource, which seems like overkill given I basically only want to change the hardcoded limit for std::pmr::pool_options.largest_required_pool_block. I also looked into how gcc implements the std::pmr::unsynchronized_pool_resource and it seemed possible to "just" copy that implementation and manually apply the changes I want, but this also feel wrong and I am unsure of how much work that would be. I could write my application, so that large allocations bypass even the std::pmr::monotonic_buffer_resource which would solve the bloat problem, but not the time-saving aspect of not having to repeatedly allocate large buffers.
Are there any other solutions to my problem? Am I simply missing something obvious? I am also a bit surprised that the std::pmr::pool_options.largest_required_pool_block has a hardcoded limit. Why does the standard not want me to freely try out larger block sizes if my application requires them?
// 4MB should be enough for anybodythat looks sloppy on libstdc++, the standard allows them to pick a limit and they picked a very low one , MSVC has almost unbounded one, and libc++ has 1 GB limit, libstdc++ uses 4 MB .... if you have to use libstdc++ then i think you need to create your own. (or find one online), otherwise you could be using libc++