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 ...
随机推荐
- 【转载】Android Studio简单设置
界面设置 默认的 Android Studio 为灰色界面,可以选择使用炫酷的黑色界面.Settings --> Appearance --> Theme ,选择 Darcula 主题即可 ...
- [原创]Java生成Word文档
在开发文档系统或办公系统的过程中,有时候我们需要导出word文档.在网上发现了一个用PageOffice生成word文件的功能,就将这块拿出来和大家分享. 生成word文件与我们编辑word文档本质上 ...
- hive 中 Order by, Sort by ,Dristribute by,Cluster By 的作用和用法
order by order by 会对输入做全局排序,因此只有一个reducer(多个reducer无法保证全局有序) 只有一个reducer,会导致当输入规模较大时,需要较长的计算时间. set ...
- (转)Excel自定义格式详解
”G/通用格式”:以常规的数字显示,相当于”分类”列表中的”常规”选项.例:代码:”G/通用格式”.10显示为10:10.1显示为10.1. 2. “#”:数字占位符.只显有意义的零而不显示无意义的零 ...
- Java AWT组件开发和Swing界面编程
一.AWT组件开发 1.AWT AWT是抽象窗口工具箱的缩写,它为编写图形用户界面提供了用户接口,通过这个接口就可以继承很多方法,省去了很多工作.AWT还能使应用程序更好地同用户进行交互. AWT中的 ...
- direction
基本上,大家只要关心下面这两个属性值就好了: direction: ltr; // 默认值 direction: rtl; 其中,ltr是初始值,表示left-to-right,就是从左往右的意思,再 ...
- 【旧文章搬运】对抗RKU的StealthCode检测
原文发表于百度空间,2009-07-02========================================================================== 快一个月没 ...
- 利用记事本和cmd进行java编程(从安装IDE--编译--运行)
java 最大特点---跨平台 所谓的跨平台性,是指软件可以不受计算机硬件和操作系统的约束而在任意计算机环境下正常运行.这是软件发展的趋势和编程人员追求的目标.之所以这样说,是因为计算机硬件的种类繁多 ...
- Asp.net MVC 中使用 Ninject 实现依赖注入
松耦合.针对抽象编程.不针对实现编程是面向对象设计的原则.依赖注入就是,在一个类的内部,不通过创建对象的实例而能够获得实现了某个公开接口的对象引用.所谓的控制反转也是相同的意思.把依赖的创建转移到了使 ...
- 洛谷 - P2055 - 假期的宿舍 - 最大流
https://www.luogu.org/problemnew/show/P2055 这是一个错误的示范. 一开始觉得就找一条路从外校同学连到本校同学然后最终从周末回家的同学流出,每个人睡后一个人的 ...