TCMalloc을 STL 컨테이너와 함께 사용하고 싶습니다. 따라서 TCMalloc (TBB malloc과 함께 tbb_allocator처럼)을 사용하여 할당자를 만들어야합니다. TCMalloc documentation (문서라고 부르는 경우)을 찾을 수 없습니다. 그래서 헤더 파일을 탐색하고 STL_Allocator
이라는 클래스를 찾습니다. 그러나 뭔가 명확하지 않습니다. stl_allocator.h에서 인용 :TCMalloc Allocator for STL
// 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()가 완벽하게 수행됩니다. –