2
我正在使用TBB自定义内存分配器。如何为动态分配的stl容器设置分配器?
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++ 11未初始化的存储与自定义分配器吗? – fish2000