为什么此编译命令显示与 valgrind 不同的内存使用情况?

Why this compilation command says a different memory usage than valgrind?

我必须为大学创建一个程序,并且有一个网站可以测试我使用了多少内存。使用相同的输入,如果我在我的电脑上编译我的程序并使用 valgrind 运行 它说总堆使用量为 77k 字节,大约 75 kib。

但是当我在网站上提交它时,使用相同的输入,内存使用结果为 384 kib,我不明白是 valgrind 在说谎还是网站是 d运行k。我怀疑我用一个简单的

编译我的程序
gcc myprog.c -o myc

虽然大学网站编译它:

/usr/bin/gcc -DEVAL -std=c11 -O2 -pipe -static -s -o program programname.c -lm

我对这个编译命令一无所知,教授只是说这是在网站上使用的,我也可以在我的电脑上使用它。 如果我使用这个编译命令,程序 运行 就很好,但是当我尝试在它创建的可执行文件上使用 valgrind 时,它停止并说它无法继续。

所以很快就会出现问题,为什么我看到分配的内存有所不同?是因为这个编译命令做了什么吗?

If i use this compilation command the program runs just fine but when i try to use valgrind on the executable file created by it, it stops and says it cannot continue

您没有提供确切的错误消息,但无论如何 Valgrind 对静态链接的二进制文件(使用 -static 选项构建)效果不佳,请参阅 Valgrind errors when linked with -static -- Why?

why do i see a difference in allocated memory?

因为您构建的是动态链接的可执行文件,而网站构建的是静态链接的可执行文件,请在 Static linking vs dynamic linking 中查看它们之间的区别。

请注意,Valgrind 并不是衡量二进制文件内存使用情况的唯一工具。您还可以使用 /usr/bin/time -v <binary_name> 并在输出中查找 Maximum resident set size