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 */ ... 例子:
文件:mal.acc

#include <stdio.h>
after(void * s) : (call($ malloc(...)) || call($ calloc(...)) || call($ realloc(...)))
&& result(s) {
char * result = (char *)(s);
if (result != NULL) {
printf(" aspectC:Memory Allocation Success ! \n");
}
else{
printf(" aspectC:Memory Allocation Faile ! \n");
}
}

文件mal.c:

#include <stdio.h>
#include <malloc.h>
void t1()
{
int *x ;
printf(" core code:hehe ! \n");
x = (int *)malloc(sizeof(int) * 4);
printf(" core code:hehe ! ! \n");
}
int main()
{
t1();
int *x ;
printf(" core code:hehe ! ! \n");
x = (int *)malloc(sizeof(int) * 4);
printf(" core code:hehe ! ! \n");
return 0;
}

A Reusable Aspect for Memory Allocation Checking的更多相关文章

  1. A Reusable Aspect for Memory Profiling

    例子: malPro.acc文件: #include <stdlib.h> size_t totalMemoryAllocated; int totalAllocationFuncCall ...

  2. Advanced Memory Allocation 内存分配进阶[转]

    May 01, 2003  By Gianluca Insolvibile  in Embedded Software Call some useful fuctions of the GNU C l ...

  3. Linux下TomcatVM参数修改:Native memory allocation (mmap) failed to map 3221225472 bytes for committing reserved memory.

    不可行的方法最初我直接修改catalina.sh, 将JAVA_OPTS变量加上了 -server -Xms1G -Xmx1G -XX:+UserG1GC最初看起来没啥问题,但是当服务器运行几天后,发 ...

  4. Memory Allocation in the MySQL Server

    https://dev.mysql.com/doc/internals/en/memory-allocation-mysql-server.html MySQL Internals Manual  / ...

  5. 内存管理(memory allocation内存分配)

    Memory management is the act of managing computer memory. The essential requirement of memory manage ...

  6. 【转】Memory gates checking failed because the free memory***解决办法

    Issue: Vault users cannot connect. VLOGS show the following error: Memory gates checking failed beca ...

  7. .NET Memory Allocation Profiling with Visual Studio 2012

    .NET Memory Allocation Profiling with Visual Studio 2012 This post was written by Stephen Toub, a fr ...

  8. Memory Allocation Error

    Memory allocation error happened when I tried to install MySQL 5.7.13 in my server, which has 2G mem ...

  9. [bug]WCF 内存入口检查失败 Memory gates checking failed

    bug描述 异常信息:内存入口检查失败,因为可用内存(xxx 字节)少于总内存的 xx%.因此,该服务不可用于传入的请求.若要解决此问题,请减少计算机上的负载,或调整 serviceHostingEn ...

随机推荐

  1. (转) Hibernate注解开发

    http://blog.csdn.net/yerenyuan_pku/article/details/70162268 Hibernate注解开发 在Hibernate中我们一般都会使用注解,这样可以 ...

  2. Discuz! G变量的使用方法

    1,G变量的使用方法: 例如:$_G['style'][boardlogo] 风格变量篇 $_G['style'] => Array (官方模板区 cr180整理 $_G['style'][st ...

  3. js输出非字符串,非null值

    console.log(!"");//非空(true) console.log(!);//非0(true) console.log(!" ");//非空格(fa ...

  4. Map 键值对 set get delete

  5. PAT (Advanced Level) Practice(更新中)

    Source: PAT (Advanced Level) Practice Reference: [1]胡凡,曾磊.算法笔记[M].机械工业出版社.2016.7 Outline: 基础数据结构: 线性 ...

  6. iview表单密码自定义验证

    From中定义   ref="passwordForm" 获取dom节点  :model="passwordForm" 关联表单数据对象 :rules=&quo ...

  7. Mac 执行 gulp 报错 -bash: gulp: command not found

    在mac系统下安装gulp,之后执行gulp 报如下错误: -bash: gulp: command not found 回溯安装过程发现问题如下 1.执行 npm root: Application ...

  8. 49.ardinality算法之优化内存开销以及HLL算法

    主要知识点 precision_threshold参数的理解 HLL算法优化(hash)         cardinality,count(distinct),5%的错误率,性能在100ms左右   ...

  9. css的基本操作学习--css样式,选择器,hover,文字属性,文本属性,背景

    什么是css? 通配符选择器 <head> /* *通配符选择器 匹配任何元素 */ *{ margin: 0; padding: 0; } </head> css样式有三种 ...

  10. UVa - 11452 - Dancing the Cheeky-Cheeky

    先上题目: F. Dancing the Cheeky-Cheeky  Context The Cheeky-Cheeky is a new song. They dance it in Mula, ...