lis05's blog

By lis05, history, 3 years ago, In English

What's going on??

Hello codeforces! Recently, i've noticed that codeforces custom test with g++ 17 uses more than 500bytes per empty std::queue, while sizeof shows only 40bytes. This problem is also with std::deque. What's going on? Compiled with GNU G++17 7.3.0

  • Vote: I like it
  • +9
  • Vote: I do not like it

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by lis05 (previous revision, new revision, compare).

»
3 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Nevermind, I misunderstood that you were comparing the computed value with the memory reported under the =====.

  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    sizeof(arr)/1000 shows size in kb, look at the second image

    sizeof(arr)/NMAX shows size in bytes for single queue

»
3 years ago, # |
Rev. 2   Vote: I like it +3 Vote: I do not like it

std::queue uses std::deque under the hood by default. And in GCC's libstdc++ standard library the latter allocates elements dynamically in chunks of ~512 bytes by default, see M_initialize_map here, plus one chunk extra. It's that extra chunk which makes std::deque weigh slightly more than 500 bytes.