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 ...
随机推荐
- mongodb c++ driver安装踩坑记
安装教程:https://mongodb.github.io/mongo-cxx-driver/mongocxx-v3/installation/ (1) “initializer_list” fil ...
- 创建一个Windows Service 程序
1.新建Windows项目,选择"Windows服务"类型的项目. 2.在生成的Service1.cs中代码中写你需要的代码,如下: using System; using Sys ...
- Linux命令排查线上问题常用的几个
排查线上问题常用的几个Linux命令 https://www.cnblogs.com/cjsblog/p/9562380.html top 相当于Windows任务管理器 可以看到,输出结果分两部分, ...
- web.xml配置之<context-param>
<context-param>的作用和用法: 1.<context-param>配置是是一组键值对,比如: <context-param> <p ...
- 如何下载WDK
随着Windows Vista和Windows Server 2008的相继发布,微软的驱动开发工具也进行了相应的更新换代.原来的驱动开发工具包叫做DDK(Driver Develpment Kit) ...
- PDB文件说明
文/玄魂 .PDB文件,全称为“程序数据库”文件.我们使用它(更确切的说是看到它被应用)大多数场景是调试应用程序.目前我们对.PDB文件的普遍认知是它存储了被编译文件的调试信息,作为符号文件存在.那么 ...
- c++ 头文件 及 sort 和 vector简单介绍
c++ sort :http://www.16kan.com/post/997260.html http://wenku.baidu.com/view/e064166daf1ffc4ffe47ac6 ...
- CoreBluetooth Central模式 Swift版
也是醉了,CB这个API到现在也没有Swift的文档.最新的文档还是3年前还是4年前的OC版的,被雷的外焦里嫩的.自己一点一点写成Swift还各种报错,最坑的是这些错误压根找不到解决方案.索性自己做个 ...
- 【Tip】JavaScript
『JavaScript』 『引用网络资源』 JQuery <script src="http://code.jquery.com/jquery-latest.js">& ...
- Fast Bit Calculations LightOJ - 1032
Fast Bit Calculations LightOJ - 1032 题意:求0到n的所有数的二进制表示中,"11"的总数量.(如果有连续的n(n>2)个1,记(n-1) ...