gpt4 book ai didi

c++ - aio.h aio_read() 和写入内存泄漏

转载 作者:太空狗 更新时间:2023-10-29 22:52:25 35 4
gpt4 key购买 nike

我正在尝试使用 C++ 异步读取和写入磁盘(使用 Ubuntu 10.04 中的 posix aio 库),遵循此处概述的说明:aio tutorial .我可以异步读写,但恐怕会出现某种小的内存泄漏。我的 valgrind 输出显示有 288 个可能丢失的字节和 3,648 个仍可访问的字节。这些数字似乎与实际从文件中读取的字节数无关。我找不到在哪里或如何消除这种泄漏——甚至看起来这是 aio 库的问题。有没有人见过这个?完整的 valgrind 输出如下。提前致谢。

==22330== ==22330== HEAP SUMMARY:==22330==     in use at exit: 3,936 bytes in 3 blocks==22330==   total heap usage: 25 allocs, 22 frees, 15,648 bytes allocated==22330== ==22330== 64 bytes in 1 blocks are still reachable in loss record 1 of 3==22330==    at 0x4C274A8: malloc (vg_replace_malloc.c:236)==22330==    by 0x4C27522: realloc (vg_replace_malloc.c:525)==22330==    by 0x504CAF1: __aio_enqueue_request (aio_misc.c:127)==22330==    by 0x504D25A: aio_read (aio_read.c:30)==22330==    by 0x406EB7: baio::read(std::string, char*, long) (baio_unix.cxx:58)==22330==    by 0x40613E: test_read_helper(char*) (test_read.cxx:16)==22330==    by 0x4063E1: test_read() (test_read.cxx:54)==22330==    by 0x40664C: test_read_main(int, char**) (test_read.cxx:74)==22330==    by 0x40959D: testlib_run_test_unit(unsigned long, int, char**) (testlib_main.cxx:116)==22330==    by 0x4097A9: testlib_main(int, char**) (testlib_main.cxx:155)==22330==    by 0x4060B4: main (test_driver.cxx:12)==22330== ==22330== 288 bytes in 1 blocks are possibly lost in loss record 2 of 3==22330==    at 0x4C267CC: calloc (vg_replace_malloc.c:467)==22330==    by 0x4012395: _dl_allocate_tls (dl-tls.c:300)==22330==    by 0x4E34728: pthread_create@@GLIBC_2.2.5 (allocatestack.c:561)==22330==    by 0x504C9A8: __aio_enqueue_request (aio_misc.h:60)==22330==    by 0x504D25A: aio_read (aio_read.c:30)==22330==    by 0x406EB7: baio::read(std::string, char*, long) (baio_unix.cxx:58)==22330==    by 0x40613E: test_read_helper(char*) (test_read.cxx:16)==22330==    by 0x4063E1: test_read() (test_read.cxx:54)==22330==    by 0x40664C: test_read_main(int, char**) (test_read.cxx:74)==22330==    by 0x40959D: testlib_run_test_unit(unsigned long, int, char**) (testlib_main.cxx:116)==22330==    by 0x4097A9: testlib_main(int, char**) (testlib_main.cxx:155)==22330==    by 0x4060B4: main (test_driver.cxx:12)==22330== ==22330== 3,584 bytes in 1 blocks are still reachable in loss record 3 of 3==22330==    at 0x4C267CC: calloc (vg_replace_malloc.c:467)==22330==    by 0x504CA27: __aio_enqueue_request (aio_misc.c:139)==22330==    by 0x504D25A: aio_read (aio_read.c:30)==22330==    by 0x406EB7: baio::read(std::string, char*, long) (baio_unix.cxx:58)==22330==    by 0x40613E: test_read_helper(char*) (test_read.cxx:16)==22330==    by 0x4063E1: test_read() (test_read.cxx:54)==22330==    by 0x40664C: test_read_main(int, char**) (test_read.cxx:74)==22330==    by 0x40959D: testlib_run_test_unit(unsigned long, int, char**) (testlib_main.cxx:116)==22330==    by 0x4097A9: testlib_main(int, char**) (testlib_main.cxx:155)==22330==    by 0x4060B4: main (test_driver.cxx:12)==22330== ==22330== LEAK SUMMARY:==22330==    definitely lost: 0 bytes in 0 blocks==22330==    indirectly lost: 0 bytes in 0 blocks==22330==      possibly lost: 288 bytes in 1 blocks==22330==    still reachable: 3,648 bytes in 2 blocks==22330==         suppressed: 0 bytes in 0 blocks

最佳答案

第二个 block 看起来像是与库拥有的线程相关联的线程本地存储,该线程是为处理异步读取而创建的。

==22330==    by 0x4012395: _dl_allocate_tls (dl-tls.c:300)
==22330== by 0x4E34728: pthread_create@@GLIBC_2.2.5 (allocatestack.c:561)

第一个和第三个看起来像是与未完成的异步读取相关联的内部结构。

如果你能在只担心这个的情况下持续奔跑一段时间,我的本能会是对小恩小惠心存感激。库肯定必须有一定的自由度来分配持久内存以关联异步读取的结果。

关于c++ - aio.h aio_read() 和写入内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4248720/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com