The following code snippet(see on godbolt) shows that big allocators won't increase the memory footprint of STL containers, but big comparators will. Why is it the case?
// compiled with x86-64 gcc 10.3, -std=c++17
#include <functional>
#include <iostream>
#include <memory>
#include <set>
struct MyLess : public std::less<int>
{
char dummy[1024];
};
struct MyAllocator : public std::allocator<int>
{
char dummy[1024];
};
int main()
{
std::cout << sizeof(std::set<int, MyLess>) << std::endl; // prints 1064
std::cout << sizeof(std::set<int, std::less<int>, MyAllocator>) << std::endl; // prints 48
return 0;
}