__BEGIN__; __END__ - [OPENCV]
2013-03-11 11:19
204 查看
文章原始出处和作者信息及本声明
http://shijuanfeng.blogbus.com/logs/205062662.html
__BEGIN__;__END__是opencv中的一种错误处理机制,它可以防止非法的内存释放,以及内存泄露
防止内存非法释放的一个例子,从opencv文档中粘出来的
http://shijuanfeng.blogbus.com/logs/196580440.html这是我之前做练习的一个例子,在最后一个改进的程序中,可以看到,写了好几遍
这句代码,用__BEGIN__;__END__就可以避免一直这样子写
不过貌似直接写个宏更简单呢,呵呵,反正也算是种方法~~~
明天年后,希望自己可以抽个奖,嘎嘎~~~今天自觉加班了快一小时,总结今天一天所学,走喽~~~
__BEGIN__;__END__是opencv中的一种错误处理机制,它可以防止非法的内存释放,以及内存泄露
#define__BEGIN__{ #define__END__gotoexit;exit:;}
防止内存非法释放的一个例子,从opencv文档中粘出来的
voidcvResizeDCT(CvMat*input_array,CvMat*output_array)
{
CvMat*temp_array=0;//declarepointerthatshouldbereleasedanyway.
CV_FUNCNAME("cvResizeDCT");//declarecvFuncName
__BEGIN__;//startprocessing.Theremaybesomedeclarationsjustafter
//thismacro,buttheycouldnotbeaccessedfromtheepilogue.
if(!CV_IS_MAT(input_array)||!CV_IS_MAT(output_array))
//useCV_ERROR()toraiseanerror
CV_ERROR(CV_StsBadArg,
"input_arrayoroutput_arrayarenotvalidmatrices");
//somerestrictionsthataregoingtoberemovedlater,maybechecked
//withCV_ASSERT()
CV_ASSERT(input_array->rows==1&&output_array->rows==1);
//useCV_CALLforsafefunctioncall
CV_CALL(temp_array=cvCreateMat(input_array->rows,
MAX(input_array->cols,
output_array->cols),
input_array->type));
if(output_array->cols>input_array->cols)
CV_CALL(cvZero(temp_array));
temp_array->cols=input_array->cols;
CV_CALL(cvDCT(input_array,temp_array,CV_DXT_FORWARD));
temp_array->cols=output_array->cols;
CV_CALL(cvDCT(temp_array,output_array,CV_DXT_INVERSE));
CV_CALL(cvScale(output_array,
output_array,
1./sqrt((double)input_array->cols*output_array->cols),0));
__END__;//finishprocessing.Epiloguefollowsafterthemacro.
//releasetemp_array.Iftemp_arrayhasnotbeenallocated
//beforeanerroroccured,cvReleaseMat
//takescareofitanddoesnothinginthiscase.
cvReleaseMat(&temp_array);
}
intmain(intargc,char**argv)
{
CvMat*src=cvCreateMat(1,512,CV_32F);
#if1/*noerrors*/
CvMat*dst=cvCreateMat(1,256,CV_32F);
#else
CvMat*dst=0;/*testerrorprocessingmechanism*/
#endif
cvSet(src,cvRealScalar(1.),0);
#if0/*change0to1tosuppresserrorhandlerinvocation*/
cvSetErrMode(CV_ErrModeSilent);
#endif
cvResizeDCT(src,dst);//ifsomeerroroccurs,themessage
//boxwillpopup,oramessagewillbe
//writtentolog,orsomeuser-defined
//processingwillbedone
if(cvGetErrStatus()<0)
printf("Someerroroccured");
else
printf("EverythingisOK");
return0;
}
if(!flag)
{
fclose(fp);
return0;
}
这句代码,用__BEGIN__;__END__就可以避免一直这样子写
不过貌似直接写个宏更简单呢,呵呵,反正也算是种方法~~~
明天年后,希望自己可以抽个奖,嘎嘎~~~今天自觉加班了快一小时,总结今天一天所学,走喽~~~
相关文章推荐
- __BEGIN__; __END__是opencv中的一种错误处理机制,它可以防止非法的内存释放,以及内存泄露
- Unbalanced calls to begin/end appearance transitions for <AllInfoViewController: 0x15627e00>.
- BEGIN_INTERFACE_PART 和 END_INTERFACE_PART
- AfxBeginThread和AfxEndThread
- [C#基础]c#中的BeginInvoke和EndEndInvoke
- BEGIN_MESSAGE_MAP 和END_MESSAGE_MAP() 这两个宏的具体实现与作用
- AfxBeginThread和AfxEndThread
- NS_ASSUME_NONNULL_BEGIN和NS_ASSUME_NONNULL_END是做什么的?
- 【转】 SQL begin end 块作用
- awk '/#BEGIN/,/#END/{next}1' 1是什么意思?
- Ruby中用begin/end …rescue…ensure … raise 来处理异常
- SQL里面的IF ELSE,没有{},使用begin...end
- Unbalanced calls to begin/end appearance transitions for 解决方法
- dx中的BeginScene/EndScene
- list(链表)常用成员(顺序容器)----插入push_back,push_front,insert删除pop_back,pop_front,erase,clear遍历begin,end判空emp
- awk的BEGIN与END模式
- Unix awk的流程控制BEGIN和END的讲解
- 语法甜点11:非成员的begin和end
- [C++]STL中vector容器 begin()与end()函数、front()与back()的用法
- mysql语句之begin end 多重嵌套