Describes memory errors in C ++ programs

Source: Internet
Author: User

This article will show you some good memory-related coding practices to keep memory errors under control. Memory errors are the root cause of C and C ++ programs: they are common and have been known to be serious for more than 20 years, but they have never been completely resolved.

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 features of good memory encoding in a short time:

The importance of correct memory management is that C and C ++ programs with incorrect memory may cause various problems. If they leak memory, the running speed will gradually slow down and the operation will eventually stop. If the memory is overwritten, the Operation will become very fragile and vulnerable to attacks by 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. However, from the 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, and correct application in practice is so difficult, 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.

  • A simple programming language-C ++
  • Relationship between hosted C ++ and non-hosted C ++
  • How to Make PHP Execute C ++ applications
  • Analysis of C ++ program changes in Visual Studio
  • Analysis of constructor in C ++

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 you migrate data to a C ++ program. Whether the data is a simple type, a C-language struct or a C ++ class, the memory management and reference models in C and C ++ are the same in principle. The vast majority of the following content is the "pure C" language. It is mainly used for exercises to extend to C ++.

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.