广联达一面
C++ 问题,多态如何体现
怎么知道指针或者引用调用哪个版本的虚函数
虚函数表什么时候生成,虚表指针什么时候生成
堆和栈的理解
递归函数不设置结束条件,会有什么现象(Win 下会跳出内存访问错误的弹窗,Linux 下会 Core dump)
如何实现栈溢出的判断
栈中会保存什么数据
一个没有返回类型,没有参数列表的函数,递归调用自己,不设返回条件,会不会内存溢出
Array new 的内存,在释放内存的时候需要注意什么
为什么忘记写 [] 不一定导致内存泄漏
如果是内置类型的动态数组,array new 有两步动作:- 分配内存,注意该内存分配只进行一次,并且会在内存中分配 cookie 标记内存大小
- 多次调用构造函数,在申请到的一大块内存中调用构造函数
因为只进行了一次内存分配,delete 会一次性释放整块内存。
而如果是自定义类型并且类示例包含指向动态内存的指针,此时因为只调用一次析构函数,会造成内存泄漏(含有指针的内存被释放)。
内存泄露的定义
内存泄漏(Memory leak)是在计算机科学中,由于疏忽或错误造成程序未能释放已经不再使用的内存。内存泄漏并非指内存在物理上的消失,而是应用程序分配某段内存后,由于设计错误,导致在释放该段内存之前就失去了对该段内存的控制,从而造成了内存的浪费。
后果
内存泄漏会因为减少可用内存的数量从而降低计算机的性能。最终,在最糟糕的情况下,过多的可用内存被分配掉导致全部或部分设备停止正常工作,或者应用程序崩溃。
内存泄漏带来的后果可能是不严重的,有时甚至能够被常规的手段检测出来。在现代操作系统中,一个应用程序使用的常规内存在程序终止时被释放。这表示一个短暂运行的应用程序中的内存泄漏不会导致严重后果。
在以下情况,内存泄漏导致较严重的后果:
聊聊熟悉的项目
你觉得你的项目哪里还可以改进
遇到问题怎么调试,比如有什么功能是用 gdb 调试才成功的
遇到段错误,怎么去找错误
你遇到的错误都是第一现场吗?(可能是想问不是第一现场怎么办,但是没有用过 coredump,也没有真的看过栈帧)