The most commonly used tool is used to detect memory problems in programs. All reading and writing to memory will be detected, and all calls to malloc, free, new, and delete will be captured. So, it can detect the following problems:
1. Use of uninitialized memory;
2. Read/write the memory block after release;
3. Read/write memory blocks exceeding malloc allocated;
4. Read/write inappropriate memory blocks in the stack;
5、Memory leak, a pointer to a piece of memory is lost forever;
6. Incorrectmalloc/freeor new/delete match;
7. The dst and src pointers in the memcpy() related function overlap.
These problems are often the most troublesome problem for C/C++ programmers, and Memcheck can help a lot here.
Analytical tools similar to gprof, but their observations on the operation of the program are more meticulous and can provide us with more information. Unlike gprof, it does not need to be compiledsource codeWhen adding special options, but adding debug options is recommended. Callgrind collects some data during the runtime of the program, establishes a function call relationship diagram, and can also selectively perform cache simulation. At the end of the run, it writes the analysis data to a file. callgrind_annotate can convert the contents of this file into readable form.
Note: I didn't use this tool either. There are basically no guiding documents found on the Internet. Let's stay here for a while and study it slowly.
Cache analyzer, which simulates Level 1 cache I1 in the CPU,Dland secondary cache, which can accurately indicate the loss and hit of cache in the program. If needed, it can also provide us with the number of cache lost times, memory references, and the number of instructions generated by each line of code, each function, each module, and the entire program. This is very helpful for the optimization program.
Make an advertisement:valgrindIt has improved performance in the past few months using the tool itself25%-30%. According to earlier reports,kdeDevelopmentteamYesvalgrindIn improvingkdeThanks for the performance help.
It is mainly used to check competition problems that arise in multithreaded programs. Helgrind looks for areas in memory that are accessed by multiple threads without consistent locking. These areas are often where threads are lost in synchronization and can lead to difficult-to-discover errors. Helgrind implements a competition detection algorithm called "Eraser" and makes further improvements to reduce the number of errors reported. However, Helgrind is still in the experimental stage.
5. Massif
Stack analyzer, it can measure how much memory the program uses in the stack, telling us the size of the heap block, heap management block and stack. Massif can help us reduce memory usage. In modern systems with virtual memory, it can also speed up the operation of our programs and reduce the chances of programs staying in the swap zone.
Massif does the allocation and release of memoryprofile. It allows program developers to gain insight into the memory usage behavior of programs, thereby optimizing memory usage. This functionC++Especially useful becauseC++There are many hidden memory allocations and releases
In addition, Lackey and nulgrind will also be available. Lackey is a small tool that is rarely used; Nulgrind is just showing developers how to create a tool. We won't introduce it.