Difficulties and secrets in C ++ programs

Source: Internet
Author: User

In fact, the memory management and reference models in C and C ++ programs are the same in principle. The following describes four categories of memory errors and memory errors: memory leakage and misallocation, including a large increase in free () memory and uninitialized references, floating pointers, and array boundary violations.

Memory Errors in C and C ++ programs are extremely harmful: they are common and may cause serious consequences. Many of the most serious security announcements from the Computer Emergency Response Team (see references) and vendors are caused by simple memory errors.

Since the end of 1970s, C programmers have been discussing such errors, but the impact is still very high in 2007. Even worse, many C and C ++ programmers may think that memory errors are uncontrollable and mysterious, and they can only be corrected, cannot be prevented.

But this is not the case. This article will allow you to understand all the nature of the Code related to good memory in a short time: the importance of correct memory management is caused by memory errors in C and C ++ programs. If they leak memory, the running speed slows down gradually and stops running. If the memory is overwritten, it becomes very vulnerable.

Attackers are vulnerable to attacks from malicious users. The latest security alerts from the famous Morris worm attack in 1988 to Flash Player and other key retail programs are related to buffer overflow: "Most computer security vulnerabilities are buffer overflow ".

Rosydney Bates wrote in 2004. Many other general languages (such as Java? Ruby, Haskell, C #, Perl, Smalltalk, etc.), each language has many enthusiasts and their respective advantages.

  • Who is more powerful in C ++ and C?
  • How to better compile C ++ code
  • Introduction to how to implement shared memory in the C ++ standard library
  • C ++ code implementation ControlTemplate
  • Analysis of Visual C ++ application implementation methods

However, from a computing point of view, the main advantages of each programming language over C or C ++ are closely related to ease of memory management. Memory-related programming is so important. In practice, it is so difficult to apply it correctly, so that it controls all other variables or theories of object-oriented programming languages, functional programming languages, advanced programming languages, declarative programming languages, and other programming languages.

Like a few common errors of other types, memory errors are a hidden hazard: they are hard to reproduce and the symptoms are usually not found in the source code. For example, whenever and wherever a memory leak occurs, it may be totally unacceptable to the application, and the memory leak is not obvious. Therefore, for all these reasons, we need to pay special attention to the memory problems of C and C ++ programming. Let's take a look at how to solve these problems. Let's not talk about the language.

Memory Error category

First, do not lose confidence. There are many ways to deal with memory problems. First, we will list all possible problems:

1. Memory leakage

2. misallocation, including a large increase in free () memory and uninitialized references

3. Floating pointer

4. array boundary Violation

This is all types. These types do not change significantly even if they are migrated to the object-oriented language of the C ++ program, whether the data is a simple type or a struct or C ++ class in the C language. The memory management and reference models in C and C ++ are the same in principle. The majority of the following content is the "pure C" language, which is mainly used for exercises to extend to the C ++ program.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.