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 ...
随机推荐
- hdu 2066 一个人的旅行 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2066 题目意思:给出T条路,和草儿家相邻的城市编号,以及草儿想去的地方的编号.问从草儿家到达草儿想去的 ...
- poj 3461 Oulipo(kmp统计子串出现次数)
题意:统计子串出现在主串中的次数 思路:典型kmp #include<iostream> #include<stdio.h> #include<string.h> ...
- ibatis 中 $与#的区别
ibatis 中 $与#的区别 使用#: select * from table where id = #id# 如果字段为整型:#id#表示成id select * from table where ...
- ASP.NET Core MVC 2.x 全面教程_ASP.NET Core MVC 07. View的Model 和 Tag Helpers
student添加一个属性BirthDate 然后把生成数据的地方,字段也加上 建立ViewModel list转换为ViewModel 进一步改进代码 StudentViewModel HomeIn ...
- 个人项目开发PSP实践-MyWCprj
MyWCprj.exe Github仓库地址 1. What is MyWCprj.exe? wc是linux下一个非常好用的代码统计小工具,可以通过 -c .-w .-l等选项分别进行对指定文件的代 ...
- SCUT - 244 - 全新的游戏 - 凸包
https://scut.online/p/244 除了常规的求凸包求面积,还有一个判断点在凸包内,先找出点所在的三角扇区. #include<bits/stdc++.h> using n ...
- poj1163 【记忆化搜索·水】
题意: 一个这样的三角形,他可以往下的左或者往下的右走.求一个在最后一行的最大. 思路: 额...就是搜一下..记录一下...肯定有重合的情况. code- //#include <bits/s ...
- POJ2446【建图建图】
题意: 给你一个n*n的矩阵,然后再给你几个坑,然后问你能否被1*2的长方形给覆盖: -弱知道了是二分匹配的做法,但是弱还是不会转化,又是在建图上GG了 分析: 从国际象棋的那个黑白色理解,这是一张二 ...
- P5162 WD与积木(多项式求逆+生成函数)
传送门 题解 比赛的时候光顾着算某一个\(n\)的答案是多少忘了考虑不同的\(n\)之间的联系了--而且我也很想知道为什么推着推着会变成一个二项式反演-- 设\(f_n\)为\(n\)块积木时的总的层 ...
- Jquery下拉框左右选择
1.说明 本文demo实现下拉框左右选择,本文地址:http://www.cnblogs.com/lengzhan/p/6423023.html 2.代码 <!DOCTYPE html PUBL ...