fork(2) download
  1. #include <iostream>
  2. #include <functional>
  3. #include <utility>
  4. #include <memory>
  5. #include <map>
  6.  
  7.  
  8. std::size_t amount = 0;
  9.  
  10.  
  11. template<typename T>
  12. struct my_allocator : std::allocator<T> {
  13.  
  14. template<typename U>
  15. struct rebind {
  16.  
  17. typedef my_allocator<U> other;
  18. };
  19.  
  20. typename std::allocator<T>::pointer allocate(std::size_t const n, std::allocator<void>::const_pointer const hint = 0) {
  21. amount += n * sizeof (T);
  22. return std::allocator<T>::allocate(n, hint);
  23. }
  24. };
  25.  
  26.  
  27. int main() {
  28. std::map<int, int, std::less<int>, my_allocator<std::pair<int const, int> > > map;
  29.  
  30. for (std::size_t i = 0; i != 10000; ++i) {
  31. map.insert(std::make_pair(i, i));
  32. }
  33.  
  34. std::cout << amount << std::endl;
  35. }
Success #stdin #stdout 0s 3736KB
stdin
Standard input is empty
stdout
240000