delete void pointer
delete void pointer是否会有内存泄漏?
看下面一个简单例子
class Test{
public:
Test(){
printf ("constructor\n");
}
~Test(){
printf("destructor");
}
}; int main(int argc, char *argv[])
{
Test *p = new Test();
void *p1 = p;
delete p1;
printf("the end\n");
getchar(); return 0;
}
结果输出:
从输出可以看出来,没有调用类的析构函数;
网上解释:
It depends on "safe." It will usually work because information is stored along with the pointer about the allocation itself, so the deallocator can return it to the right place. In this sense it is "safe" as long as your allocator uses internal boundary tags. (Many do.)
However, as mentioned above, deleting a void pointer will not call destructors, which can be a problem. In that sense, it is not "safe."
参考:http://stackoverflow.com/questions/941832/is-it-safe-to-delete-a-void-pointer
delete void pointer的更多相关文章
- Pointer arithmetic for void pointer in C
http://stackoverflow.com/questions/3523145/pointer-arithmetic-for-void-pointer-in-c When a pointer t ...
- 【ThinkingInC++】65、使用delete void*可能会出错
/** * 书本:[ThinkingInC++] * 功能:使用delete void*可能会出错 * 时间:2014年10月5日14:31:43 * 作者:cutter_point */ #incl ...
- 微信SDK导入报错 Undefined symbols for architecture i386:"operator delete[](void*)", referenced from:
异常信息: Undefined symbols for architecture i386: "operator delete[](void*)", referenced fro ...
- differences between null pointer and void pointer.
These are two different concepts, you cannot compare them. What the difference between the skunk and ...
- delete void *
看代码的时候看到 typedef char xxx[sizeof(T) ? 1 : -1]; 这种语句 如:JavaScriptCore/wtf/OwnPtrCommon.h template < ...
- 不要轻易delete void*指针,这样会隐藏比较多的错误。
#include<iostream> using namespace std; class Object{ void* data; const int size; const char i ...
- javascript特殊运算符(in,instanceof,typeof,delete,void,逗号)
in运算符 in运算符要求其左边的运算数是一个字符串,或可以被转换为字符串,右边的运算数十一个对象或数组.如果该 运算符左边的值是右边对象的一个属性名,则返回true, ...
- C++ 重载new和delete操作符
原因: C++标准库提供的new和delete操作符,是一个通用实现,未针对具体对象做具体分析 存在分配器速度慢.小型对象空间浪费严重等问题,不适用于对效率和内存有限制的应用场景 好处: 灵活的内 ...
- 重载全局new/delete实现内存检测
下面介绍用重载new/delete运算符的方式来实现一个简单的内存泄露检测工具,基本思想是重载全局new/delete运算符,被检测代码调用new和delete运算符时就会调用重载过的operator ...
随机推荐
- 贪心算法: Codevs 1052 地鼠游戏
#include <iostream> #include <algorithm> #include <queue> #include <cstring> ...
- HDU 2988 Dark roads (裸的最小生成树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2988 解题报告:一个裸的最小生成树,没看题,只知道结果是用所有道路的总长度减去最小生成树的长度和. # ...
- CentOS7 关闭防火墙和selinux
本文将简单介绍在CentOS7上如何临时和永久关闭防火墙和selinux. 关闭防火墙 # 查看防火墙状态 [root@localhost ~]# systemctl status firewalld ...
- C++ 修饰符类型
C++ 修饰符类型 C++ 允许在 char.int 和 double 数据类型前放置修饰符.修饰符用于改变基本类型的含义,所以它更能满足各种情境的需求. 下面列出了数据类型修饰符: signed u ...
- keepalived vrrp_script脚本不执行解决办法
首先打开日志观察: tail -f /var/log/messages 然后新开一个客户端重启keepalived , systemctl restart keepalived.service 看日志 ...
- mysql innobackupex 备份及恢复
----------------------------------全量备份恢复-------------------------------------1.生成一个完整的备份 innobackupe ...
- 【Linux高级驱动】input子系统框架【转】
转自:http://www.cnblogs.com/lcw/p/3802617.html [1.input子系统框架(drivers\input)] 如何得出某个驱动所遵循的框架? 1) 通过网 ...
- 安装Python3.6.4后,在使用numpy时报错RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88
原因: 因为安装numpy用的是 pip来安装的 pypi官方对于numpy的库已经升级了,但是升级后的版本与其他的库不匹配 所以报错 解决: 先把已经安装的numpy卸载: pip uninstal ...
- Scala工具库
1. Scala json解析库:https://github.com/json4s/json4s
- NTP多种模式的配置
自己安装和配置了一个NTP服务器的一些心得,希望与大家分享.写了一个文档包含了各个命令和参数的具体含义,由于不能上传无法与大家分享.以后还希望大家多多支持和帮助我们共同成长,我会不断做把这些年的经营和 ...