Linux C Programming Memory leak tool: Use of Memwatch

Source: Internet
Author: User

1. First you need to download it in http://www.linkdata.se/sourcecode/memwatch/

2. The memory tool is open source (I also like open source ^_^ ...), no need to install, just include its header file in your code. Like this #include "Memwatch"

3. The latest version currently used is memwatch-2.71.tar.gz

4. Unzip TAR-XVF memwatch-2.71.tar.gz

5. Copy memwatch.c and MEMWATCH.H to your program directory in the unzip file

6. The test file contains Testmem.c, MEMWATCH.C, memwatch.h

7. Test the code:

1#include <stdio.h>2#include <stdlib.h>3#include <errno.h>4#include"memwatch.h"5 intMain ()6 {7         Char*Hello;8Setenv"Malloc_trace","Output",1);9 mtrace ();Ten         if(Hello = (Char*) malloc (sizeof(Char))) ==NULL) One         { APerror ("cannot allocate memory"); -                 return-1; -         } the         return 0; -}
View Code

8. Test command:

Gcc-dmemwatch-dmw_stdio testmem.c Memwatch.c-o Testmem

9. Run./Testmem

10. Generate Memwatch.log and view the cat Memwatch.log

As to what kind of principle, we can read the source code and the Readme file

Linux C Programming Memory leak tool: Use of Memwatch

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.