摘要
为了获得最佳性能,C/C++语言把操纵内存的权限以指针的方式暴露给开发人员。但是C/C++语言编译器GCC和Clang都不提供内存安全检测,导致开发人员使用C/C++语言编写的项目可能存在内存泄漏的风险。文章介绍了改进指针算法和shared_ptr源码,分析了它们检测内存泄漏的方式,最后指出该类算法的缺陷,提出改进思路,并建议用户避免写出该类算法无法检测的代码结构。
In order to obtain the best performance, C/C++ language exposes the permission to manipulate memory to developers in the form of pointers. However, the C/C++ language compiler GCC and Clang do not provide memory security detection, which leads to the risk of memory leakage for projects written by developers in C/C++ language. This paper introduces the improved pointer algorithm and shared_ptr source code, analyzes their ways to detect memory leakage, finally points out the defects of this kind of algorithm and puts forward improvement ideas, and advises users to avoid writing code structures that cannot be detected by such algorithms.
作者
仵俊
WU Jun(College of Computer Science and Technology,Nanjing University of Aeronautics and Astronautics,Nanjing 211100,China)
出处
《现代信息科技》
2021年第22期98-100,共3页
Modern Information Technology
基金
国家自然科学基金:内存安全性和形式化规约的运行时验证(62172217)。