2013年8月1日 星期四

Valgrind 來監看 記憶體 大小

使用方法
Valgrind  -v   ./a.out


 跑完的結果會出現

Total Execution Time = 110.06 seconds
==31065==
==31065== HEAP SUMMARY:
==31065==     in use at exit: 2,591,288 bytes in 23,679 blocks
==31065==   total heap usage: 128,904 allocs, 105,225 frees, 15,854,055 bytes allocated
==31065==
==31065== Searching for pointers to 23,679 not-freed blocks
==31065== Checked 162,024 bytes
==31065==
==31065== LEAK SUMMARY:
==31065==    definitely lost: 912,142 bytes in 2,531 blocks
==31065==    indirectly lost: 1,679,146 bytes in 21,148 blocks
==31065==      possibly lost: 0 bytes in 0 blocks
==31065==    still reachable: 0 bytes in 0 blocks
==31065==         suppressed: 0 bytes in 0 blocks
==31065== Rerun with --leak-check=full to see details of leaked memory
==31065==
==31065== Use --track-origins=yes to see where uninitialised values come from
==31065== ERROR SUMMARY: 706490 errors from 2 contexts (suppressed: 4 from 4)
==31065==
==31065== 355 errors in context 1 of 2:
==31065== Conditional jump or move depends on uninitialised value(s)
==31065==    at 0x42D712: tree::Two_Maxc_in_one_part(Partition&) (tree.cpp:534)
==31065==    by 0x42F983: tree::get_info_from_onetree(int) (tree.cpp:374)
==31065==    by 0x42F9C4: tree::Sample_tree() (tree.cpp:322)
==31065==    by 0x42FE02: tree::SIS_tree() (tree.cpp:262)
==31065==    by 0x40306C: BSP_tree(std::vector<std::string, std::allocator<std::string> >) (main.cpp:841)
==31065==    by 0x407EEC: main (main.cpp:61)
==31065==
==31065==
==31065== 706135 errors in context 2 of 2:  表示出現錯誤了 !!!!  下面附上 trace tree 
==31065== Invalid read of size 8
==31065==    at 0x42D705: tree::Two_Maxc_in_one_part(Partition&) (tree.cpp:534)
==31065==    by 0x42F983: tree::get_info_from_onetree(int) (tree.cpp:374)
==31065==    by 0x42F9C4: tree::Sample_tree() (tree.cpp:322)
==31065==    by 0x42FE02: tree::SIS_tree() (tree.cpp:262)
==31065==    by 0x402C8B: BSP_tree(std::vector<std::string, std::allocator<std::string> >) (main.cpp:791)
==31065==    by 0x407EEC: main (main.cpp:61)
==31065==  Address 0x518de48 is 0 bytes after a block of size 8 alloc'd
==31065==    at 0x4A0666E: operator new(unsigned long) (vg_replace_malloc.c:220)
==31065==    by 0x41158C: __gnu_cxx::new_allocator<double>::allocate(unsigned long, void const*) (new_allocator.h:88)
==31065==    by 0x4115B4: std::_Vector_base<double, std::allocator<double> >::_M_allocate(unsigned long) (stl_vector.h:127)
==31065==    by 0x417386: std::vector<double, std::allocator<double> >::_M_fill_insert(__gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, unsigned long, double const&) (vector.tcc:357)
==31065==    by 0x417594: std::vector<double, std::allocator<double> >::insert(__gnu_cxx::__normal_iterator<double*, std::vector<double, std::allocator<double> > >, unsigned long, double const&) (stl_vector.h:658)
==31065==    by 0x417632: std::vector<double, std::allocator<double> >::resize(unsigned long, double) (stl_vector.h:426)
==31065==    by 0x42DE52: tree::Region_Create(Region_Node*, Region_Node*, Region_Node*, int) (tree.cpp:466)
==31065==    by 0x42F066: tree::rand_choose_one_nextleveltree(int) (tree.cpp:816)
==31065==    by 0x42FB2C: tree::Sample_tree() (tree.cpp:334)
==31065==    by 0x42FE02: tree::SIS_tree() (tree.cpp:262)
==31065==    by 0x402C8B: BSP_tree(std::vector<std::string, std::allocator<std::string> >) (main.cpp:791)
==31065==    by 0x407EEC: main (main.cpp:61)
==31065==
--31065--
--31065-- used_suppression:      4 dl-hack3
==31065==
==31065== ERROR SUMMARY: 706490 errors from 2 contexts (suppressed: 4 from 4)
有兩個 error 




如果  答案正確無誤  沒有問題的話
就會出現類似這樣的結果

Total Execution Time = 110.29 seconds
==31093==
==31093== HEAP SUMMARY:
==31093==     in use at exit: 2,591,288 bytes in 23,679 blocks
==31093==   total heap usage: 128,904 allocs, 105,225 frees, 15,854,055 bytes allocated
==31093==
==31093== Searching for pointers to 23,679 not-freed blocks
==31093== Checked 162,024 bytes
==31093==
==31093== LEAK SUMMARY:
==31093==    definitely lost: 912,142 bytes in 2,531 blocks
==31093==    indirectly lost: 1,679,146 bytes in 21,148 blocks
==31093==      possibly lost: 0 bytes in 0 blocks
==31093==    still reachable: 0 bytes in 0 blocks
==31093==         suppressed: 0 bytes in 0 blocks
==31093== Rerun with --leak-check=full to see details of leaked memory
==31093==
==31093== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)
--31093--
--31093-- used_suppression:      4 dl-hack3
==31093==
==31093== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)

error summary = 0 



4 則留言:

  1. http://blog.csdn.net/bendanban/article/details/7741208

    回覆刪除
  2. http://blog.csdn.net/wzzfeitian/article/details/8567030

    回覆刪除
  3. http://endlesschildhood.blogspot.tw/2010/01/valgrind-tutorial.html

    回覆刪除
  4. http://valgrind.org/docs/manual/faq.html#faq.deflost

    回覆刪除