C++毕业设计外文翻译--修正内存问题
《C++毕业设计外文翻译--修正内存问题》由会员分享,可在线阅读,更多相关《C++毕业设计外文翻译--修正内存问题(7页珍藏版)》请在毕设资料网上搜索。
1、Fixing Memory Problems This chapter is about finding bugs in C/C+ programs with the help of a memory debugger. A memory debugger is a runtime tool designed to trace and detect bugs in C/C+ memory management and access. It does not replace a general debugger. In the following sections, we will descri
2、be the memory access bugs that typically occur in C/C+ programs, introduce memory debuggers, and show with two examples how these tools find bugs. We will then show how to run memory and source code debuggers together, how to deal with unwanted error messages by writing a suppression file, and what
3、restrictions need to be considered. 4.1 Memory Management in C/C+ Powerful but Dangerous The C/C+ language is able to manage memory resources, and can access memory directly through pointers. Efficient memory handling and “programming close to the hardware” are reasons why C/C+ replaced assembly lan
4、guage in the implementation of large software projects such as operating systems, where performance and low overhead play a major role. The allocation of dynamic memory (also known as heap memory) in C/C+ is under the control of the programmer. New memory is allocated with functions such as malloc()
5、 and various forms of the operator new. Unused memory is returned with free() or delete. The memory handling in C/C+ gives a large degree of freedom, control, and performance, but comes at a high price: the memory access is a frequent source of bugs. The most frequent sources of memory access bugs a
6、re memory leaks, incorrect use of memory management, buffer overruns, and reading uninitialized memory. 33 34 4 Fixing Memory Problems 4.1.1 Memory Leaks Memory leaks are data structures that are allocated at runtime, but not deallocated once they are no longer needed in the program. If the leaks ar
7、e frequent or large, eventually all available main memory in your computer will be consumed. The program will first slow down, as the computer starts swapping pages to virtual memory, and then fail with an out-of-memory error. Finding leaks with a general debugger is difficult because there is no ob
8、vious faulty statement. The bug is that a statement is missing or not called. 4.1.2 Incorrect Use of Memory Management A whole class of bugs is associated with incorrect calls to memory management: freeing a block of memory more than once, accessing memory after freeing it, or freeing a block that w
9、as never allocated. Also belonging to this class is using delete instead of delete for C+ array deallocation, as well as using malloc() together with delete, and using new together with free(). 4.1.3 Buffer Overruns Buffer overruns are bugs where memory outside of the allocated boundaries is overwri
10、tten, or corrupted. Buffer overruns can occur for global variables, local variables on the stack, and dynamic variables that were allocated on the heap with memory management. One nasty artifact of memory corruption is that the bug may not become visible at the statement where the memory is overwrit
11、ten. Only later, another statement in the program will access this memory location. Because the memory location has an illegal value, the program can behave incorrectly in a number of ways: the program may compute a wrong result, or, if the illegal value is in a pointer, the program will try to acce
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中设计图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C+ 毕业设计 外文 翻译 修正 内存 问题
