Блог пользователя AliHeidary1381

Автор AliHeidary1381, история, 7 лет назад, По-английски

I was getting a strange bug in my code. The buggy part of my code is the following:

1st Code

It gives the following error:

cc1plus.exe: out of memory allocating 134221823 bytes

And of course, I have 128 MB of free memory (It's more than 4 GB free).

But I thought that the problem might be from std::array, and I was right. So when I modified my code as:

2nd Code

The code compiles without any error. I am using MinGW w64 7.3.0 from here (it's exactly the codeforces's compiler, so the code get's compilation error when submitting) but other compilers haven't this problem (like CLang LLVM). Where do you think the problem is and why? And how can I solve it?

  • Проголосовать: нравится
  • +14
  • Проголосовать: не нравится

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

This is actually an issue with pair<> rather than std::array. pair<> doesn't make use of C++'s memcpy optimization due to some implementations in the standard libraries. You should probably see a similar result if you use pair<> within a vector as well. So for anyone reading this probably what it means for you is don't use pair<> within any container with large sizes because C++ will give no fucks and won't optimize it because it lacks =default