TCMalloc Allocator for STL

I want to use TCMalloc with STL containers, so I need a dispenser built using TCMalloc (e.g. tbb_allocator with TBB malloc). I can find nothing TCMalloc Documentation (if this is called documentation). Therefore, I begin to study the header files and find a class called STL_Allocator. But something is not clear to me. Quote from stl_allocator.h:

// 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.

And the definition of the template class STL_Allocator:

template <typename T, class Alloc>
class STL_Allocator {
//...
}

I have no idea what an argument is Alloc. Should I write a wrapper class for some memory allocation functions? Has anyone used TCMalloc?

+3
source share
2 answers

STL_Allocator TCMalloc - : ( ) Alloc, Allocate Free, , -voila- , STL ( STL ).

simple_alloc, Null Set , TCMalloc : MyAllocator memory_region_map.h.

, , , STL_Allocator, TCMalloc.

, , TCMalloc ++: malloc() - TCMalloc . GNU ++, #include <ext/malloc_allocator.h> , malloc() .

+6

, , malloc .

#include <cstdlib.h>

struct simple_alloc {
    static void* Allocate(size_t size){
        return malloc(size);
    }
    static void Free(void* ptr, size_t size){
        free(ptr);
    }
}
+1

All Articles