Access Violations Access Conflict (AVS) is the most troublesome error that occurred in Windows programming?

zhaozj2021-02-08  231

Access ViOLATIONS

Access conflict

A. Introduction

B. AVS during design

a. Hardware reasons

b. Software reasons

C. Library error

d. Upgrade C Builder

C. AVS during operation

a. AVS occurs when the program exits

b. Set your pointer to an empty pointer!

c. Use IDE management!

d. Use Cafree in Form!

e. Random AVS (non-exit)

D. More recommendations made by users

Introduction

Access Conflict (AVS) is one of the most troublesome errors that occur when Windows programming. Although it is difficult to use an article to explain the reason why it is possible to lead to AVS, I will explain all the reasons I know as much as possible. If you have a solution to the AVS not mentioned herein, please email to the author. Your experience will be added herein.

There are two main forms of AVS that occur in C Builder. AVS during design during the design of AVS during operation. Let's start discussing.

AVS during design

The AVS during the design is easier to capture, but it is difficult to really remove it. They are usually generated when compiling, when Builder is started and closed, or almost random. Let's discuss the following reasons.

Hardware reasons

Some graphics cards, dual processor motherboards, and sound devices can cause AVS in C Buider. why? Each board in your machine has a device driver. Due to manufacturers, Windows versions, there is a compatibility problem in the C Builder version you use, it will cause AVS issues. The steps to solve this situation are as follows:

o always uses the latest drivers for your system components. If you use the driver belled with Windows, you should get the latest upgrade version from the manufacturer.

o Access the newsgroup on borland.com and dejanews.com to find the topic about your hardware device. Some graphics cards are known to have compatibility issues. You may need to replace the hardware. Hardware provided by the stable and mature manufacturer used by the people is a good idea. Matrox is a good example of a graphics card.

o Checking whether there is a conflict between the devices you have installed is a must step.

o For some weird graphics drivers, sometimes the resolution is conducive to stability.

o If you use the dual processor, make sure that both processors' step revision is the same, it is to use the exact same two chips.

Software reasons

Although Windows is the most widely used operating system in the Intel system, its history is full of bugs, unstable. There are many ways to help you have a more stable programming workstation. Press the following steps to prevent you to prevent this class AVS.

o Disables Active Desktop on Windows Workstations with Internet Explorer (IE) 4.x or later. Although this feature allows you to customize your desktop, but also causing many applications to generate problems.

o Although Windows 9X is more popular, NT4 (NT5) provides almost the most stable environment in all Windows platforms. I would like to emphasize that this should be the environment selected by the C Builder programmer.

o Make sure the latest NT system patch (SPX) is installed, each release of patch makes your NT system more stable.

o Reinstall the latest SPX after upgrading the primary software package. Including MS Office, IE, even after the C Builder is installed, some SPX updated files are often overwritten when the driver is installed. If the SPX question is replaced with an old version, it will reply if there is no.

o Our experience is that when you find a new system, after a period of time, more and more problems (including AVS), reloading systems can solve the vast majority of issues and improve the overall performance of the system. This may take time, but absolutely effective. Library error

After installing new libraries and components, you should track and see if there is a correction of AVS during the design. If you have a new AVS, you may want to uninstall the recently installed components. If the AVS also disappears, seek support for suppliers.

At the same time, it should pay more attention to the ReadMe file and the installation profile. If you upgrade a library, this may need you to change your incrude directory settings, and even modify your make files to make the new and old versions have no conflict. If possible and the upgrade program allows you to uninstall the old version first, then upgrade.

Upgrade C Builder

I can guarantee that I don't work for Inprise, and I have not got any benefits. I can't emphasize the importance of using the new version of C Builder. The number of AVS is especially the AVS during the design, which is greatly reduced after I upgrade from CB3 to CB4 (now CB5). At the same time, performance is improved, there are more resources available. If you want to run, the upgrade is worth it.

AVS during operation

Although tracking is a nightmare, AVS during operation can be resolved, which is usually not the bugs described in C Builder. Before I start to help you solve the problem in your code, you must read and learn about the AVS message during the design. The recommendations in this section are only role in the AVS during operation. In particular, pay attention to whether your incrude directory contains the latest upgraded libraries, which is often the culprit. If these can't solve your problem, let us discuss programming, you should solve your problem, let you return to work.

AVS occurs when the program exits

If you have already seen your programs exit, the pop-up AVS dialog box, then congratulations, you are now like sharing a setback of the C Builder programmer (including me). Such AVS is the most difficult to track. Because DEBUGER usually introduces the rear brackets that you introduce deeply inductible VCL or simply point to engineering CPP files. But don't be afraid, the following things will help you walk through your worst worst the worst part.

Set your pointer to an empty pointer!

One biggest reason that leads to AV is to try to delete an illegal pointer. The reason for what happens may use a pointer without initialization or trying to delete it twice. If you follow the following guidance, you can reduce the AVS of 50% in your program. For all pointers, do the following:

1. Declare the pointer, set it to NULL. If you don't do this, you don't immediately use the New Action to this pointer. Otherwise, when the program exits and executes the delete action, the address of the pointer will become meaningless. Then you get an AV.

2. After deleting a pointer, set it to NULL. Although the DELETE action has been cleared, it does not clear the pointer address. If the pointer is later deleted, it will cause an AV.

Remember to delete a NULL null pointer is not wrong, it will not bring side effects.

Use IDE management!

If you have created an object that belongs to (OWNED BY), let Owner delete this object. Confused? Allow me to give an example of explanation. If you dynamically create a panel object and set it Owner to a Form (TPANEL MyPANEL = New TPANEL (TPANEL MyPANEL = New TPANEL (TPANEL MyPANEL = New TPANEL (TPANEL MyPANEL = New TPANEL (TPANEL MYPANEL = New TPANEL (THIS). This will try to delete your Panel when Owner (FORM) is deleted. If you have deleted ..., wow, av. So, when you set an object and set its OWNER in the constructor, don't manually remove this object, let Builder do. If you have to do this, make sure you set it to NULL. Use Cafree in Form!

If you can, do not manually delete the dynamically created Form instance, and use cafree in its exit event. Although this does not necessarily solve your access conflict (AVS) problem, you can separate this reason. Because AV will happen instead of when the program exits.

Random AVS (non-exit)

Creating a program list not only spends a lot of time, but I am likely to be included in the problem you encounter. But there is still a small part of the most common AV code question:

o Try to access the position other than the length of the string. For example, the string is NULL empty ("") and attempts to access the first character mystr [1] of the string.

o Reference an empty pointer. Possible reasons: The pointer should be New, but the pointer has been deleted before being accessed, the local and global pointers are the same name, the overall or partial pointer, but the other is accessed.

More suggestions proposed by users

One way to prevent access to the empty pointer problem is to always check all the pointers before deciding to use the pointer to do anything. There are many ways to implement. The best way is probably using Assert, in fact, if the IF (MyPTR! = Null) {...} is also good. It is worth noting that the multi-level, the IF method can also work well. This is to thank the C language to support the jump (Boolean value short circuit) on the first false value of the "IF" predicate. Such as: if (myptr! = Null && myptr-> itsptr! = Null && myptr-> itsptr-> ptr2! = Null) {....

In the example below INT * PARRAY = New Int [2]; PARRAY [0] = 1; parray [1] = 2; parray [2] = 2; overflow !! A number of items only apply for 8 Bytes ... Pop-up the usual AV dialog (the one with red x). Instead, a dialog that does not have an icon is popped, and the CPU window is also popped up. So, when you see a similar situation, you can know that there are array overflow ....

转载请注明原文地址:https://www.9cbs.com/read-2222.html

New Post(0)