现在的位置: 首页 > 综合 > 正文

vs2010 visual leak detector 配置方法 和 静态指针的释放 vs2010 visual leak detector 配置方法 和 静态指针的释放

2014年01月24日 ⁄ 综合 ⁄ 共 2296字 ⁄ 字号 评论关闭

vs2010 visual leak detector 配置方法 和 静态指针的释放


130人阅读
评论(0)
收藏
举报

使用visual leak detector 方法(本例使用2.2版本)

1从http://vld.codeplex.com/releases下载安装包,安装。

2配置方法见http://vld.codeplex.com/wikipage?title=Using%20Visual%20Leak%20Detector&referringTitle=Documentation

   ① 点击View
->Property Manager,

②双击打开Microsoft.Cpp.Win32.user.

   ③选择 VC++
Directories

④在"Include
directories"
 选择安装路径visual
leak detector\include文件夹

⑤在"Library
directories" 选择安装
路径visual
leak detector\lib\
Win32 文件夹(如果64位机器选择win64文件夹)

3测试

#include "vld.h"

int _tmain(int argc, _TCHAR* argv[])
{
TCHAR* pChTem = (TCHAR*)malloc(7*sizeof(TCHAR));

TCHAR* pChTem2= (TCHAR*)malloc(7*sizeof(TCHAR));

TCHAR* pChTem3 = (TCHAR*)malloc(7*sizeof(TCHAR));

MessageBox(NULL, _T("visual leak delect"), NULL, MB_OK);

return 0;
}


静态成员函数想要调用非静态程序函数,必须传递该类的一个对象:创建的线程的回调函数可以使用静态函数(这是静态函数调用非静态函数的一个例子)。

静态指针变量的动态分配和删除  转自http://blog.csdn.net/nellson/article/details/5738629

  1. #include <unistd.h>  
  2. #include <stdio.h>  
  3.   
  4. class CPointer  
  5. {  
  6.     public:  
  7.         CPointer(){};  
  8.         ~CPointer(){};  
  9.     public:  
  10.         static char * m_p;  
  11. };  
  12.   
  13. char * CPointer::m_p = NULL;  
  14.   
  15. void proc()  
  16. {  
  17.     for(int i = 0; i < 10; i++)  
  18.     {  
  19.         if (NULL != CPointer::m_p)  
  20.         {  
  21.             char * p = CPointer::m_p;  
  22.             delete []p;  
  23.             p = NULL;  
  24.             CPointer::m_p = NULL;  
  25.         }  
  26.         CPointer::m_p = new char[1024*1024];  
  27.         sleep(1);  
  28.     }  
  29. }  
  30.   
  31. int main(int argc, char ** argv)  
  32. {  
  33.     proc();  
  34.     return 0;      

使用visual leak detector 方法(本例使用2.2版本)

1从http://vld.codeplex.com/releases下载安装包,安装。

2配置方法见http://vld.codeplex.com/wikipage?title=Using%20Visual%20Leak%20Detector&referringTitle=Documentation

   ① 点击View
->Property Manager,

②双击打开Microsoft.Cpp.Win32.user.

   ③选择 VC++
Directories

④在"Include
directories"
 选择安装路径visual
leak detector\include文件夹

⑤在"Library
directories" 选择安装
路径visual
leak detector\lib\
Win32 文件夹(如果64位机器选择win64文件夹)

3测试

#include "vld.h"

int _tmain(int argc, _TCHAR* argv[])
{
TCHAR* pChTem = (TCHAR*)malloc(7*sizeof(TCHAR));

TCHAR* pChTem2= (TCHAR*)malloc(7*sizeof(TCHAR));

TCHAR* pChTem3 = (TCHAR*)malloc(7*sizeof(TCHAR));

MessageBox(NULL, _T("visual leak delect"), NULL, MB_OK);

return 0;
}


静态成员函数想要调用非静态程序函数,必须传递该类的一个对象:创建的线程的回调函数可以使用静态函数(这是静态函数调用非静态函数的一个例子)。

静态指针变量的动态分配和删除  转自http://blog.csdn.net/nellson/article/details/5738629

  1. #include <unistd.h>  
  2. #include <stdio.h>  
【上篇】
【下篇】

抱歉!评论已关闭.