内存位置 0x0071f6a0 处的 std::bad_std bad allocc

程序运行一段时间挂掉:std::bad_alloc-CSDN论坛
程序运行一段时间挂掉:std::bad_alloc
连续运行程序遇到以下问题:
电脑一共8G内存,程序连续运行,运行一段时间后内存会缓慢增加,后来就会挂掉,可是挂掉时内存还有3G左右;
错误信息:
线程&'Thread&(pooled)'&(0x3140)&已退出,返回值为&0&(0x0)。
bnc.exe&中的&0x&处最可能的异常:&Microsoft&C++&异常:&内存位置&0x&处的&std::bad_alloc。
bnc.exe&中的&0x&处最可能的异常:&Microsoft&C++&异常:&内存位置&0x&处的&[rethrow]。
bnc.exe&中的&0x&处最可能的异常:&Microsoft&C++&异常:&内存位置&0x&处的&[rethrow]。
bnc.exe&中的&0x&处最可能的异常:&Microsoft&C++&异常:&内存位置&0x&处的&[rethrow]。
bnc.exe&中的&0x&处最可能的异常:&Microsoft&C++&异常:&内存位置&0x&处的&[rethrow]。
bnc.exe&中的&0x&处有未经处理的异常:&Microsoft&C++&异常:&内存位置&0x&处的&std::bad_alloc。
挂掉时的堆栈:
&& KernelBase.dll!()&
& [下面的框架可能不正确和/或缺失,没有为&KernelBase.dll&加载符号]
& KernelBase.dll!()&
& msvcr100d.dll!_unlock(int&locknum)&&行&375 C
& msvcr100d.dll!_realloc_dbg(void&*&pUserData,&unsigned&int&nNewSize,&int&nBlockUse,&const&char&*&szFileName,&int&nLine)&&行&1044&+&0x7&字节 C++
& msvcr100d.dll!_realloc_dbg(void&*&pUserData,&unsigned&int&nNewSize,&int&nBlockUse,&const&char&*&szFileName,&int&nLine)&&行&1043&+&0xc&字节 C++
有人说用堆栈来调试,可是就这么几行没办法来呀,请高人指点一下可能的错误原因,如何查错,谢谢!!!!!!!!!!
还是解决内存、资源泄露吧!
看着像内存泄漏导致的,把这个解决了再说吧。
一个进程的内存分为用户空间和内核空间,Windows应该也是这么划分的,应用程序只能申请应用空间的内存
另外,楼主说挂掉的时候还有3G内存,应该操作系统还有3G物理内存没有映射出去
再说一点,应用程序new申请的内存,都是内核从内存空间,注意是内存空间,不是真正的内存,分配出来的
内存泄漏。。&
可以循环调用某段代码,&查看windows任务管理器,&观察内存变化情况,&确认是否泄漏、
有内存泄露了
没有delete或者free
祝你好运吧............
申请了动态内存空间后常常会忘记在不用的时候释放,这样会造成内存的浪费等其他问题。
怎样检查你的代码有没有内存泄露呢?&需要在前面加上这些代码:
#ifdef&_DEBUG
#define&DEBUG_CLIENTBLOCK&&&new(&_CLIENT_BLOCK,&__FILE__,&__LINE__)
#define&DEBUG_CLIENTBLOCK
#define&_CRTDBG_MAP_ALLOC
#include&&stdlib.h&
#include&&crtdbg.h&
#include&&string.h&
#include&&stdio.h&
#ifdef&_DEBUG
#define&new&DEBUG_CLIENTBLOCK
然后在要检测的代码前面加上:
_CrtSetDbgFlag&(&_CRTDBG_ALLOC_MEM_DF&|&_CRTDBG_LEAK_CHECK_DF&);
在后面加上:
_CrtDumpMemoryLeaks();
-------------------------------------------------------------------*/
#ifdef&_DEBUG
#define&DEBUG_CLIENTBLOCK&&&new(&_CLIENT_BLOCK,&__FILE__,&__LINE__)
#define&DEBUG_CLIENTBLOCK
#define&_CRTDBG_MAP_ALLOC
#include&&stdlib.h&
#include&&crtdbg.h&
#include&&string.h&
#include&&stdio.h&
#ifdef&_DEBUG
#define&new&DEBUG_CLIENTBLOCK
int&main()
&&&&_CrtSetDbgFlag&(&_CRTDBG_ALLOC_MEM_DF&|&_CRTDBG_LEAK_CHECK_DF&);
&&&&int&*p;
&&&&p&=&new&
&&&&_CrtDumpMemoryLeaks();
&&&&return&0;
/*----------------------------------------------------------------
然后按F5进行调试,会发现输出框中显示:
Detected&memory&leaks!
Dumping&objects&-&
e:\microsoft&visual&c++\myprojects\临时\main.cpp(20)&:&{41}&client&block&at&0x,&subtype&0,&4&bytes&long.
Data:&&&&&&&&CD&CD&CD&CD
Object&dump&complete.
Detected&memory&leaks!
Dumping&objects&-&
e:\microsoft&visual&c++\myprojects\临时\main.cpp(20)&:&{41}&client&block&at&0x,&subtype&0,&4&bytes&long.
Data:&&&&&&&&CD&CD&CD&CD
Object&dump&complete.
The&thread&0xD18&has&exited&with&code&0&(0x0).
就说明有内存泄露。解决的方法是把代码改成:
&&&&int&*p;
&&&&p&=&new&
&&&&delete&p;
就可以解决内存泄露的问题了。(及时释放)2009年7月 总版技术专家分月排行榜第二2009年3月 总版技术专家分月排行榜第二2009年1月 总版技术专家分月排行榜第二2005年7月 总版技术专家分月排行榜第二2005年5月 总版技术专家分月排行榜第二2005年3月 总版技术专家分月排行榜第二
优秀小版主2015年8月优秀小版主2015年9月优秀小版主2015年5月优秀小版主2015年2月论坛优秀版主
2017年9月 VC/MFC大版内专家分月排行榜第二2017年8月 VC/MFC大版内专家分月排行榜第二2017年4月 VC/MFC大版内专家分月排行榜第二2017年3月 VC/MFC大版内专家分月排行榜第二2017年2月 VC/MFC大版内专家分月排行榜第二2016年8月 VC/MFC大版内专家分月排行榜第二2016年7月 VC/MFC大版内专家分月排行榜第二2016年6月 VC/MFC大版内专家分月排行榜第二2015年6月 VC/MFC大版内专家分月排行榜第二
2017年10月 VC/MFC大版内专家分月排行榜第三2017年6月 VC/MFC大版内专家分月排行榜第三2017年5月 VC/MFC大版内专家分月排行榜第三2016年9月 VC/MFC大版内专家分月排行榜第三2016年4月 VC/MFC大版内专家分月排行榜第三2015年4月 VC/MFC大版内专家分月排行榜第三2012年8月 VC/MFC大版内专家分月排行榜第三
2013年 总版技术专家分年内排行榜第三
2012年 总版技术专家分年内排行榜第七
本帖子已过去太久远了,不再提供回复功能。2013年 总版技术专家分年内排行榜第三
2012年 总版技术专家分年内排行榜第七
匿名用户不能发表回复!|
每天回帖即可获得10分可用分!小技巧:
你还可以输入10000个字符
(Ctrl+Enter)
请遵守CSDN,不得违反国家法律法规。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。利于OPENCV实现分割算法的问题【opencv吧】_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:8,784贴子:
利于OPENCV实现分割算法的问题收藏
// meanshift_segmentation.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include &opencv2/core/core.hpp&#include &opencv2/highgui/highgui.hpp&#include &opencv2/imgproc/imgproc.hpp&#include &iostream&#include&stdio.h&Mat src,int spatialRad=10,colorRad=10,maxPryLevel=1; //10 10 1const Scalar& colorDiff=Scalar::all(1); void meanshift_seg(int,void *) // void *{//调用meanshift图像金字塔进行分割pyrMeanShiftFiltering(src,dst,spatialRad,colorRad,maxPryLevel);RNG rng=theRNG();Mat mask(dst.rows+2,dst.cols+2,CV_8UC1,Scalar::all(0));for(int i=0;i&dst.i++) //opencv图像等矩阵也是基于0索引的for(int j=0;j&dst.j++)if(mask.at&uchar&(i+1,j+1)==0){Scalar newcolor(rng(256),rng(256),rng(256));floodFill(dst,mask,Point(i,j),newcolor,0,Scalar::all(1),Scalar::all(1));// floodFill(dst,mask,Point(i,j),newcolor,0,colorDiff,colorDiff);}imshow("dst",dst);} int main(int argc, uchar* argv[]){namedWindow("src",WINDOW_AUTOSIZE);namedWindow("dst",WINDOW_AUTOSIZE);src=imread("left.png");CV_Assert(!src.empty());spatialRad=10;colorRad=10;maxPryLevel=1;//虽然createTrackbar函数的参数onChange函数要求其2个参数形式为onChange(int,void*)//但是这里是系统响应函数,在使用createTrackbar函数时,其调用的函数可以不用写参数,甚至//括号都不用写,但是其调用函数的实现过程中还是需要满足(int,void*)2个参数类型createTrackbar("spatialRad","dst",&spatialRad,80,meanshift_seg);createTrackbar("colorRad","dst",&colorRad,60,meanshift_seg);createTrackbar("maxPryLevel","dst",&maxPryLevel,5,meanshift_seg);meanshift_seg(0,0);imshow("src",src);/*char c=(char)waitKey();if(27==c)return 0;*/imshow("dst",src); waitKey();//无限等待用户交互响应while(1);//这里不能用while(1)的原因是需要等待用户的交互,而while(1)没有该功能。虽然2者都有无限等待的作用。return 0;} /*这个基本上是opencv附带的meanshift分割算法 ,但是运行时总提示异常: 内存位置 0x002ff030 处的 std::bad_alloc。*/ // meanshift_segmentation.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include &opencv2/core/core.hpp&#include &opencv2/highgui/highgui.hpp&#include &opencv2/imgproc/imgproc.hpp&#include &iostream&#include&stdio.h&Mat src,int spatialRad=10,colorRad=10,maxPryLevel=1; //10 10 1const Scalar& colorDiff=Scalar::all(1); void meanshift_seg(int,void *) // void *{//调用meanshift图像金字塔进行分割pyrMeanShiftFiltering(src,dst,spatialRad,colorRad,maxPryLevel);RNG rng=theRNG();Mat mask(dst.rows+2,dst.cols+2,CV_8UC1,Scalar::all(0));for(int i=0;i&dst.i++) //opencv图像等矩阵也是基于0索引的for(int j=0;j&dst.j++)if(mask.at&uchar&(i+1,j+1)==0){Scalar newcolor(rng(256),rng(256),rng(256));floodFill(dst,mask,Point(i,j),newcolor,0,Scalar::all(1),Scalar::all(1));// floodFill(dst,mask,Point(i,j),newcolor,0,colorDiff,colorDiff);}imshow("dst",dst);} int main(int argc, uchar* argv[]){namedWindow("src",WINDOW_AUTOSIZE);namedWindow("dst",WINDOW_AUTOSIZE);src=imread("left.png");CV_Assert(!src.empty());spatialRad=10;colorRad=10;maxPryLevel=1;//虽然createTrackbar函数的参数onChange函数要求其2个参数形式为onChange(int,void*)//但是这里是系统响应函数,在使用createTrackbar函数时,其调用的函数可以不用写参数,甚至//括号都不用写,但是其调用函数的实现过程中还是需要满足(int,void*)2个参数类型createTrackbar("spatialRad","dst",&spatialRad,80,meanshift_seg);createTrackbar("colorRad","dst",&colorRad,60,meanshift_seg);createTrackbar("maxPryLevel","dst",&maxPryLevel,5,meanshift_seg);meanshift_seg(0,0);imshow("src",src);/*char c=(char)waitKey();if(27==c)return 0;*/imshow("dst",src); waitKey();//无限等待用户交互响应while(1);//这里不能用while(1)的原因是需要等待用户的交互,而while(1)没有该功能。虽然2者都有无限等待的作用。return 0;} /*这个基本上是opencv附带的meanshift分割算法 ,但是运行时总提示异常: 内存位置 0x002ff030 处的 std::bad_alloc。*/
AutoTDS-V1型全自动热解吸仪是一款20位常温二次全自动热解吸仪,气路采....
楼主手一抖粘多了,还有一个是比较基本的分水岭算法,仍然是在VS2008debug中显示异常,0x002ff030 处的 std::bad_alloc楼下贴出代码
#include&cv.h&
#include&highgui.h&
#include&iostream&
int main(){ IplImage* imgTest = cvLoadImage("C:\\Users\\Administrator\\Desktop\\2.bmp",0);
CvMemStorage* storage = cvCreateMemStorage(0);
CvSeq* lines = 0;
lines = cvHoughLines2( imgTest, storage, CV_HOUGH_STANDARD,1,CV_PI/180, 5, 0, 0 );
float* line = (float*)cvGetSeqElem(lines,0);
float rho = line[0];
// distance from (0,0) to the line
float theta = line[1];
// angle between x-axis and the normal to the line
double thetaDegree = theta/3.;
IplImage* imgRes = cvCreateImage(cvSize(imgTest-&width,imgTest-&height),IPL_DEPTH_8U,3);
cvSetZero(imgRes);
double a,b,c;
// ax+by+c=0
if (theta&CV_PI/2)
theta = CV_PI-
if (theta&CV_PI/4)
a = 1/tan(theta);
c = rho/sin(theta);
b = -tan(theta);
c = rho/cos(theta);
if (theta&CV_PI/4)
a = -1/tan(theta);
c = rho/sin(theta);
b = -tan(theta);
c = rho/cos(theta);
if (abs(a)&abs(b))
// using x = -b/a*y-c/a
for (int h=0;h&imgRes-&h++)
int w = -b/a*h-c/a;
if (w&imgRes-&width && w&=0)
imgRes-&imageData[h*imgRes-&widthStep+3*w] = 255;
// using y = -a/b*x-c/b
for (int w=0;w&imgRes-&w++)
int h = -a/b*w-c/b;
if (h&imgRes-&height && h&=0)
imgRes-&imageData[h*imgRes-&widthStep+3*w] = 255;
cvSaveImage("C:\\Users\\Administrator\\Desktop\\dhjg.bmp",imgRes);
cvReleaseImage(&imgRes);
cvReleaseImage(&imgTest);
return 0;}
楼主,无法打开源文件 &stdafx.h&是怎么回事?我用的2010版本。。刚接触opencv,不太明白
登录百度帐号推荐应用

我要回帖

更多关于 内存位置0x00aef790 的文章

 

随机推荐