简体   繁体   English

使用 std::ios::sync_with_stdio(fasle) 打印时,在 Valgrind 的 LEAK SUMMARY 中获取“仍然可达”

[英]Getting a "still reachable" in LEAK SUMMARY in Valgrind when using std::ios::sync_with_stdio(fasle) to print out

Consider the simple code below:考虑下面的简单代码:

#include <iostream>
#include <algorithm>
#include <vector>

void print_vector( const std::vector<int> &inputVector )
{
    std::ios_base::sync_with_stdio(false);

    for ( const int &p : inputVector )
    {
        std::cout << p << "  ";
    }

    std::cout << "\n";
}

int main() {

    std::vector<int> s{ 5, 7, 4, 2, 8, 6, 1, 9, 0, 3 };

    std::sort( s.begin(), s.end(), [](const int &a, const int &b)
    {
        return a > b;
    });

    print_vector( s );

    return 0;
}

When using the above printing function I get a "still reachable" in the LEAK SUMMARY when profiling with valgrind.使用上述打印功能时,在使用 valgrind 进行分析时,我会在 LEAK SUMMARY 中看到“仍然可以访问”。

I used the following for compiling: (gcc version 9)我使用以下进行编译:(gcc 版本 9)

g++ --std=c++17 -Wall sorting_stl.cc -o sorting_stl.o

and the following valgrind command和以下 valgrind 命令

valgrind --leak-check=full --show-leak-kinds=all -v ./sorting_stl.o 

The full LEAK SUMMARY at the end:完整的泄漏总结在最后:

LEAK SUMMARY:
    definitely lost: 0 bytes in 0 blocks
    indirectly lost: 0 bytes in 0 blocks
      possibly lost: 0 bytes in 0 blocks
    still reachable: 122,880 bytes in 6 blocks
         suppressed: 0 bytes in 0 blocks

Removing the std::ios::sync_with_stdio(false);删除std::ios::sync_with_stdio(false); and using std::endl;并使用std::endl; resolves the error.解决错误。 I don't understand the reason though why this happens, or if it is an error here.我不明白为什么会发生这种情况,或者这里是否有错误。 Is it a good idea in general to use std::sync_with_stdio(false);通常使用std::sync_with_stdio(false);

It's fine.没关系。

This counts as a "false positive";这算作“误报”; some aspects of the standard library deliberately don't do clean-up.标准库的某些方面故意不进行清理。 This is one of them. 这是其中之一。

It's not a leak that'll get worse over time.这不是随着时间的推移会变得更糟的泄漏。 Don't worry about it.别担心。

Ideally Valgrind would be neighbourly and would filter this out, but apparently it's been an issue for a long time .理想情况下,Valgrind 应该是友好的,并且会过滤掉它,但显然它已经存在很长时间了

You can read more about the various report levels in the Valgrind FAQ .您可以在 Valgrind 常见问题解答中阅读有关各种报告级别的更多信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用sync_with_stdio时的打印顺序 - Print order when using sync_with_stdio Valgrind 抱怨使用 std::ios_base::sync_with_stdio( false ) 的程序可能存在 memory 问题,为什么? - Valgrind complaining for possible memory problems from a program which uses std::ios_base::sync_with_stdio( false ) why? std::ios_base::sync_with_stdio(false),优点,缺点? - std::ios_base::sync_with_stdio(false), advantages, disadvantages? 使用std :: ios :: sync_with_stdio(false)可以比scanf和printf更快吗? - Using std::ios::sync_with_stdio(false) can be faster than scanf and printf? 由于使用 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 得到错误输出在代码中 - Getting error outputs due to using ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); in the code 当使用&#39;ios :: sync_with_stdio(0)&#39;测试运行时差异时,为什么我的输出碎片化了? - When using ' ios::sync_with_stdio(0)' for testing difference in runtime, why is my output fragmented? Valcurnd中仍然可以获得libcurl C ++代码的泄漏摘要 - Still reachable leak summary in Valgrind for libcurl c++ code ios_base::sync_with_stdio 优化 - ios_base::sync_with_stdio optimization 为什么在libc ++(clang)中没有实现std :: ios_base :: sync_with_stdio? - Why std::ios_base::sync_with_stdio isn't implemented in libc++ (clang)? 为什么我需要在 main 中写 std::ios::sync_with_stdio ? - Why do I need to write std::ios::sync_with_stdio inside main?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM