简体   繁体   中英

C++14 RAM Usage

On submitting a solution on SPOJ, I've found that my program used 16M of memory even though my program used a single integer variable.

Is this natural or am I missing something?

#include <iostream>

int main(void)
{
    int x;
    while(true)
    {
        std::cin >> x;
        if(x == 42)
        {
            break;
        }
        std::cout << x << "\n";
    }
    return 0;
}

The compiler used is gcc 6.

提交信息

This is fairly natural if you're running with debug info (the strip command in a makefile will pull that out) and if you're building optimized or non-optimized.

Try adding -s and -O to your GCC command if not already. This will build your executable optimized to a decent degree and strip the symbol tables from the executable as well as a few other things. Should reduce your memory usage significantly.

If you want further optimizations on your memory you can also custom set the stack size with GCC, you can try to reduce it to the KB to make some ground there too.

All in all for an unoptimized/debug loaded executable this is fairly normal.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM