Thanks @JérômeRichard and everyone. I misprinted in for-loops conditions. Should be x
x <=limit
and y*y
<= limit
instead of x <= limit
and y <= limit
. Everything else (dynamic array, array data type, I/O stream and etc.) plays zero role in my case. Now all primes up to 10Millions are found within ~2-3 seconds. I made such mistake because I thought I transferred code from PHP clearly and my eyes just 'skipped' this moment every time I reviewed this part of C++ code. I am not lazy, but my brain is =)
P.S. I made all necessary corrections to C++ code in my Question.