我想使用TCMalloc和STL容器,所以我需要一个使用TCMalloc构建的分配器(如tbb_allocator和TBB malloc)。我找不到任何东西TCMalloc documentation(如果它被称为文档)。所以我开始探索头文件并找到一个名为STL_Allocator
的类。但有些事情我不清楚。从stl_allocator.h报价:STL的TCMalloc分配器
// Generic allocator class for STL objects
// that uses a given type-less allocator Alloc, which must provide:
// static void* Alloc::Allocate(size_t size);
// static void Alloc::Free(void* ptr, size_t size);
//
// STL_Allocator<T, MyAlloc> provides the same thread-safety
// guarantees as MyAlloc.
//
// Usage example:
// set<T, less<T>, STL_Allocator<T, MyAlloc> > my_set;
// CAVEAT: Parts of the code below are probably specific
// to the STL version(s) we are using.
// The code is simply lifted from what std::allocator<> provides.
而且STL_Allocator模板类的定义是:
template <typename T, class Alloc>
class STL_Allocator {
//...
}
我不知道该Alloc
说法可能是什么。我是否应该为某些内存分配函数编写包装类?任何人使用TCMalloc?
恐怕我正在使用MSVC,并且更换'malloc'是一项艰巨的任务。另外,我需要在应用程序中快速分配两个类,即使其中一个放置新'new(tcmalloc :: alloc())ClassNAme()'也会完美。 – 2011-04-07 21:18:09