dimanche 4 février 2018

How to use GCC provided allocator (e.g. malloc_allocator, debug_allocator,__pool_alloc)?

By default GGC use `new_allocator. How can I use other allocators such as debug_allocator/malloc_allocator?

I did something like this:

typedef std::basic_string<char, std::char_traits<char>,  __gnu_cxx::malloc_allocator<char>> Malloc_String;


Malloc_String s("Hello!");

But got this error:

/usr/include/c++/4.9/bits/basic_string.h: In instantiation of 'class std::basic_string<char, std::char_traits<char>, __gnu_cxx::malloc_allocator<char> >':
11:21:   required from here
/usr/include/c++/4.9/bits/basic_string.h:114:63: error: invalid use of incomplete type 'struct __gnu_cxx::malloc_allocator<char>'
       typedef typename _Alloc::template rebind<_CharT>::other _CharT_alloc_type;

Aucun commentaire:

Enregistrer un commentaire