首页 > Web开发 > 详细

A Reusable Aspect for Memory Allocation Checking

时间:2015-06-09 16:41:42      阅读:280      评论:0      收藏:0      [点我收藏+]

The checking logic would be refactored into an aspect file, as follows:

after(void * s) : (call($ malloc(...)) || call($ calloc(...)) || call($ realloc(...))) 
			&& result(s) {
	char * result = (char *)(s);
	if (result == NULL) {
		/* routine to handle the case when memory allocation fails */
	}
} 


Now, the core program looks as follows:

...
int *x ;
x = (int *)malloc(sizeof(int) * 4);		<--- dynamic memory allocation
/* routine for handling the normal case */

...

A Reusable Aspect for Memory Allocation Checking

原文:http://www.cnblogs.com/xiaohuihui123/p/4563753.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!