A Reusable Aspect for Memory Allocation Checking
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的更多相关文章
- A Reusable Aspect for Memory Profiling
例子: malPro.acc文件: #include <stdlib.h> size_t totalMemoryAllocated; int totalAllocationFuncCall ...
- Advanced Memory Allocation 内存分配进阶[转]
May 01, 2003 By Gianluca Insolvibile in Embedded Software Call some useful fuctions of the GNU C l ...
- Linux下TomcatVM参数修改:Native memory allocation (mmap) failed to map 3221225472 bytes for committing reserved memory.
不可行的方法最初我直接修改catalina.sh, 将JAVA_OPTS变量加上了 -server -Xms1G -Xmx1G -XX:+UserG1GC最初看起来没啥问题,但是当服务器运行几天后,发 ...
- Memory Allocation in the MySQL Server
https://dev.mysql.com/doc/internals/en/memory-allocation-mysql-server.html MySQL Internals Manual / ...
- 内存管理(memory allocation内存分配)
Memory management is the act of managing computer memory. The essential requirement of memory manage ...
- 【转】Memory gates checking failed because the free memory***解决办法
Issue: Vault users cannot connect. VLOGS show the following error: Memory gates checking failed beca ...
- .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 ...
- Memory Allocation Error
Memory allocation error happened when I tried to install MySQL 5.7.13 in my server, which has 2G mem ...
- [bug]WCF 内存入口检查失败 Memory gates checking failed
bug描述 异常信息:内存入口检查失败,因为可用内存(xxx 字节)少于总内存的 xx%.因此,该服务不可用于传入的请求.若要解决此问题,请减少计算机上的负载,或调整 serviceHostingEn ...
随机推荐
- 您厉害您赚得多:聪明投资者的聊天记录,雪球CEO的21条投资理念
3星|<您厉害您赚得多>:雪球创始人的投资理念.原则.技巧,及其在雪球上跟一些用户的互动的内容 作者是雪球创始人.CEO,全书基本是作者的一些投资理念+作者在雪球上跟用户的互动的内容,还有 ...
- js输出非字符串,非null值
console.log(!"");//非空(true) console.log(!);//非0(true) console.log(!" ");//非空格(fa ...
- Memcached 之PHP实现服务器集群一致性hash算法
/** * memcached 一致性hash,分布式算法 * Class MemcacheCluster */ class MemcacheCluster { protected $nodes = ...
- CAD绘制一个直径标注(com接口VB语言)
主要用到函数说明: _DMxDrawX::DrawDimDiametric 绘制一个直径标注.详细说明如下: 参数 说明 DOUBLE dChordPointX 在被标注的曲线上的第一个点X值 DOU ...
- Error from server at http://127.0.0.1:8983/solr/xxx: undefined field type
undefined field type就是说没有定义type类型,这样情况下,可以新建一个带type的索引,比如:{type:1, id:1, name:"张三"}
- elasticsearch学习(1)简单查询与聚合
elastic 被用作全文搜索.结构化搜索.分析以及这三个功能的组合 一个ElasticSearch集群可以包含多个索引, 每个索引包含多个类型 一个类型存储着多个文档 每个文档又有多个属性 索引(名 ...
- 洛谷 3203 HNOI2010 BOUNCE 弹飞绵羊
[题解] 这道题可以用Link-Cut Tree写.. 首先建立一个虚拟节点N+1,$i$与$N+1$连边表示$i$被弹飞了 对于修改操作,先$cut(i,min(n+1,i+k[i]))$,然后再$ ...
- eclipse 下使用 git
一.默认仓库文件夹 二.window -->perspective --> customize perspective 三.提交时,要忽略的文件
- Postman做http接口功能测试
首先,做接口测试前要有明确的接口文档(e.g. http://test.nnzhp.cn/wiki/index.php?doc-view-59) ,假设已经在PC上安装好了Postman. 1. 普通 ...
- Master Nginx(8) - Troubleshooting Techniques
Analyzing log files Error log file formats Error log file entry examples Configuring advanced loggin ...