__attribute__ ((cleanup(xxx))) -- gcc extension
来源:互联网 发布:兄弟连php pdf 编辑:程序博客网 时间:2024/05/13 14:14
在C中如何实现C++中smart pointer的部分功能,即当变量离开它作用域时自动destroy/free?在Linux下,可以使用gcc的扩展__attribute__ ((cleanup(xxx))) 。
举例,
#define local_type __attribute__ ((cleanup(my_free)))
static void my_free(void* pmem)
{
void** ppmem = (void**) pmem;
free(*ppmem);
}
int foo(void)
{
local_type int* p = (int*) malloc(sizeof(int));
//
// use *p
// when return, the memory block pointed by p is freed automatically
return 0;
}
举例,
#define local_type __attribute__ ((cleanup(my_free)))
static void my_free(void* pmem)
{
void** ppmem = (void**) pmem;
free(*ppmem);
}
int foo(void)
{
local_type int* p = (int*) malloc(sizeof(int));
//
// use *p
// when return, the memory block pointed by p is freed automatically
return 0;
}
- __attribute__ ((cleanup(xxx))) -- gcc extension
- gcc的扩展__attribute__ ((cleanup(xxx))) 用于动态分配对象的自动释放
- 黑魔法__attribute__((cleanup))
- 黑魔法__attribute__((cleanup))
- 黑魔法__attribute__((cleanup))
- 黑魔法__attribute__((cleanup))
- __attribute__ gcc
- GCC __attribute__
- gcc __attribute__(())
- GCC __attribute__ (转载)
- GCC __attribute__((constructor)|(destructor))
- GCC编译关键字“__attribute__”
- gcc的一些 __attribute__
- Gcc __attribute__参数介绍
- gcc __attribute__ 引言
- Gcc扩展:__attribute__((constructor))
- GCC __attribute__ 选项
- gcc 中的"__attribute__ ((packed))"
- java集合架构
- Cannot load mod_jk.so
- 最隐晦的程序设计指引(转)
- 如何配置Eclipse进行Perl开发
- hibernate配置文件hibernate.cfg.xml
- __attribute__ ((cleanup(xxx))) -- gcc extension
- 存储过程(一)-----格式框架
- svn 命令
- svn 命令及其示例
- 使用MapAndLoad来看可执行文件的段结构
- Plugin file and functions
- ural 1020 Rope
- linux修改计算机名
- 在Spring DM中使用Annotations发布和引用服务