How `delete’ works ?
这是2013年写的一篇旧文,放在gegahost.net上面 http://raison.gegahost.net/?p=21
February 16, 2013
How `delete’ works ?
(original works by Peixu Zhu)
1. case of class without virtual destructor.
- calling desctructors from child to parent as a chain, which destructor to call is determined at compiling time according to the type of the instance.
- call `free‘ function to free the memory, given the address of the instance.
2. case of class with virtual destructor.
- check the virtual pointer table, and call the destructor in table. when the destructor finish working, it will replace the virtual pointer table with it’s parent’s virtual pointer table, and then calling it’s parent’s desctructor like a chain.
- after chained calling of desctructors, call `free‘ function to free the allocated memory, given the address of instance minus sizeof(void*).
3. case of arrayed instances without virtual destructor.
- check address of first instance minus sizeof(void*), to get the count of cells/instances, (i.e., `n’).
- call each instance’s destructor, from n-1 to 0.
- call `free‘ function to free the allocated memory, given the address of the first instance minus sizeof(void*).
4. case of arrayed instances with virtual destructor.
- check address of first instance minus sizeof(void*), to get the count of cells/instances, (i.e., `n’).
- call each instance’s chained destructor, from n-1 to 0.
- call `free‘ function to free the allocated memory, given the address of the first instance minus sizeof(void*).
5. calling virtual desctructors.
after finish working code in the destructor function, if there’s parent
class, and the parent class has virtual destructor, set the virtual
pointer table to be the virtual pointer table of parent class, then call
the parent class’s destructor recursively like a chain. This is a must,
because virtual methods called in virtual parent desctrutor should be
the version in parent class.
How `delete’ works ?的更多相关文章
- MTK Android 计算器Calculator输入暗码!77!+,启动工厂测试apk
Android8.0 计算器Calculator输入暗码!77!+,启动工厂测试apk 路径: packages/apps/ExactCalculator/src/com/android/calcul ...
- 如果调用ASP.NET Web API不能发送PUT/DELETE请求怎么办?
理想的RESTful Web API采用面向资源的架构,并使用请求的HTTP方法表示针对目标资源的操作类型.但是理想和现实是有距离的,虽然HTTP协议提供了一系列原生的HTTP方法,但是在具体的网络环 ...
- MySQL主从复制中断,报“Error on master: message (format)='Cannot delete or update a parent row: a foreign key constraint fails' error code=1217” 错误
前几天,发现从库挂了,具体报错信息如下: 分析思路 1. 因为我采用的是选择性复制,只针对以下几个库进行复制: card,upay,deal,monitor,collect.所以,不太可能出现对于sa ...
- [Hive - LanguageManual] DML: Load, Insert, Update, Delete
LanguageManual DML Hive Data Manipulation Language Hive Data Manipulation Language Loading files int ...
- How to Programmatically Add/Delete Custom Options in Magento? - See more at: http://apptha.com/blog/
In this tutorial, I would like to help out Magento developers and clients with how to programmatical ...
- elasticsearch6.7 05. Document APIs(5)Delete By Query API
4.Delete By Query API _delete_by_query API可以删除某个匹配条件的文档: POST twitter/_delete_by_query { "query ...
- How Autofs Works
How Autofs Works Autofs is a client-side service that automatically mounts the appropriate file syst ...
- using the library to generate a dynamic SELECT or DELETE statement mysqlbaits xml配置文件 与 sql构造器 对比
https://github.com/mybatis/mybatis-dynamic-sql MyBatis Dynamic SQL What Is This? This library is ...
- after modifying system headers, please delete the module cache at
5down votefavorite 2 I don't know how I modified a iOS SDK file, but Xcode say I did. Here is what t ...
随机推荐
- 让振动器振动起来——Vibrator的使用
AndroidManifest.xml 获取系统权限 <uses-permission android:name="android.permission.VIBRATE"/& ...
- c++11实现DLL帮助类
用过DLL的人都会发现,在C++中调用dll中的函数有点繁琐,调用过程如下:在加载dll后还要定义一个对应的函数指针类型,接着调用GetProcAddress获取函数地址,再转成函数指针,最后调用函数 ...
- 【POJ 3580】 SuperMemo
[题目链接] 点击打开链接 [算法] 本题也是Splay区间操作的模板题,不过要比BZOJ 3223要稍微复杂一些,做完此题后,我终于对Splay有了更深入的理解,有“拨开云雾见青天”的感觉 本题还是 ...
- react之fetch请求json数据
Fetch下载 npm install whatwg-fetch -S Fetch请求json数据 json文件要放在public内部才能被检索到
- 默认action和ActionSupport
默认action: <action></action>中的name属性值与<default-action-ref></default-action-ref&g ...
- springboot读写分离--temp
我最初的想法是: 读方法走读库,写方法走写库(一般是主库),保证在Spring提交事务之前确定数据源. 保证在Spring提交事务之前确定数据源,这个简单,利用AOP写个切换数据源的切面,让他的优先级 ...
- Linux学习—退出vi编辑模式
转载自:http://blog.csdn.net/u010648555/article/details/50676647 初学Linux的时候,在使用vi 操作时候,有时候可能进入的是一个文件夹,这样 ...
- mfc设置半透明对话框
BOOL CDialog7::OnInitDialog() { CDialog::OnInitDialog(); // TODO: 在此添加额外的初始化 ::SetWindowLong(GetSafe ...
- POJ 1384【完全背包】
题意: 已知储蓄罐满时的质量f以及空时质量e, 有n种硬币,每种硬币的价值为p,质量为w, 求该储蓄罐中的最少有多少钱? 思路: 完全背包思想,问题是在一个重量下的最小价值 那么只要变一下符号就好了? ...
- 洛谷 P4125 [WC2012]记忆中的水杉树【扫描线+set+线段树】
我没有找到能在bzojAC的代码--当然我也WA了--但是我在洛谷过了,那就假装过了吧 minmax线段树一开始写的只能用min更新min,max更新max,实际上是可以互相更新的-- 首先看第二问, ...