title: C++ STL: Why allocators don't increase memory footprint of containers?
body: <p>The following code snippet(<a href="https://godbolt.org/z/jqcx1xff1" rel="nofollow noreferrer">see on godbolt</a>) shows that big allocators won't increase the memory footprint of STL containers, but big comparators will. Why is it the case?</p>
  <pre class="lang-c++ prettyprint-override"><code>// compiled with x86-64 gcc 10.3, -std=c++17
  #include &lt;functional&gt;
  #include &lt;iostream&gt;
  #include &lt;memory&gt;
  #include &lt;set&gt;
  
  struct MyLess : public std::less&lt;int&gt;
  {
      char dummy[1024];
  };
  
  struct MyAllocator : public std::allocator&lt;int&gt;
  {
      char dummy[1024];
  };
  
  int main()
  {
      std::cout &lt;&lt; sizeof(std::set&lt;int, MyLess&gt;) &lt;&lt; std::endl;  // prints 1064
      std::cout &lt;&lt; sizeof(std::set&lt;int, std::less&lt;int&gt;, MyAllocator&gt;) &lt;&lt; std::endl;  // prints 48
      return 0;
  }
  
  </code></pre>