Take the 2-minute tour ×

According to this link, gcc provides lots of interesting memory allocators to be used with STL containers, but which is used by default if I don't specify one when creating a std::list?

share|improve this question
I imagine the compiler doesn't do anything about memory allocators; I expect it leaves all memory allocation to the linker/loader and runtime libc and libstdc++ libraries. –  sarnold Jun 10 '11 at 2:09
add comment

2 Answers

up vote 5 down vote accepted

As it says on that page you link to,

The current default choice for allocator is __gnu_cxx::new_allocator.

I.e, the default allocator is basically just operator new.

share|improve this answer
I think I missed it... thanks –  lvella Jun 10 '11 at 2:46
It actually depends on an option that can be passed to GCC's configure script (--enable-libstdcxx-allocator), so your answer is not necessarily true. –  Fanael Jun 10 '11 at 16:23
add comment

As per wiki :"The default allocator uses operator new to allocate memory.[13] This is often implemented as a thin layer around the C heap allocation functions,[14] which are usually optimized for infrequent allocation of large memory blocks"

from "ISO/IEC (2003). ISO/IEC 14882:2003(E): Programming Languages - C++" (wiki reference)

Default Allocator:

namespace std {   
  template <class T> class allocator;  
  // specialize for void: template <> class allocator<void>   
   typedef void*    pointer;   
   typedef const void* const_pointer;
   // reference-to-void members are impossible. typedef void value_type;  

template <class T> class allocator  
  typedef size_t size_type;  
  typedef ptrdiff_t difference_type;  
  typedef T* pointer;  
  typedef const T* const_pointer;  
  typedef T& reference;  
  typedef const T& const_reference;  
  typedef T template value_type;  

  allocator() throw();  
  allocator(const allocator&) throw();  
  ̃allocator() throw();
   pointer address(reference x) const;      
  const_pointer address(const_reference x) const;`    

  pointer allocate(  
     size_type, allocator<void>::const_pointer hint = 0);  
     void deallocate(pointer p, size_type n);  
     size_type max_size() const throw();  
     void construct(pointer p, const T& val);  
     void destroy(pointer p);  
share|improve this answer
is it incorrect ? reasons for down vote? –  Tatvamasi Jun 10 '11 at 2:38
+1 to counter the unfair down vote. –  OneOfOne Jun 10 '11 at 2:39
I think because the question is specifically about gcc, and because your answer is in terms of the standard, it doesn't exactly answer the question. –  Ernest Friedman-Hill Jun 10 '11 at 2:40
What wiki is this from? –  lvella Jun 10 '11 at 2:47
Just checked the allocator source of libstdc++ (The GNU Standard C++ Library v3) , it adheres to the standard mentioned. can have a look at it gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-3.4/…. –  Tatvamasi Jun 10 '11 at 2:59
show 2 more comments

Your Answer


