【发布时间】:2016-09-16 22:14:41
【问题描述】:
我正在使用 TBB 自定义内存分配器。
tbb::memory_pool<std::allocator<char>> shortTermPool;
typedef tbb::memory_pool_allocator<Result*> custom_allocator;
std::vector<Result*,custom_allocator>* results =(std::vector<Result*,custom_allocator>*)shortTermPool.malloc(sizeof(std::vector<Result*,custom_allocator>));
问题是在构造函数中设置分配器。 Malloc 不调用构造函数。默认用法是这样的:
tbb::memory_pool<std::allocator<char>> shortTermPool;
typedef tbb::memory_pool_allocator<Result*> custom_allocator;
std::vector<Result*,custom_allocator> results (custom_allocator(shortTermPool));
有没有办法做一个 stl 容器的 malloc,然后分配一个自定义分配器?
【问题讨论】:
标签: c++ c++11 memory-management tbb