为什么此代码片段在为构造函数设置时遇到段错误,而在不设置所述参数的情况下运行良好?min_alloc_size
boost::pool<>
这是代码片段:
#include <boost/pool/pool.hpp>
#include <iostream>
int main()
{
boost::pool<> pool_a(1024*128);
boost::pool<> pool_b(1024*128, 5*1024*1024);
auto get_mem_blk = [](boost::pool<>& pool)
{
char* ptr = (char*)pool.ordered_malloc();
pool.ordered_free(ptr);
//memset(ptr, 0, 128 * 1024);
};
get_mem_blk(pool_a); //works well
std::cout << "pass first test" << std::endl;
get_mem_blk(pool_b); //segment fault!
std::cout << "pass second test" << std::endl;
}
这是输出:
pass first test
bash: line 7: 8617 Segmentation fault (core dumped) ./a.out