Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How does java avoid using temporary variables? Java temporary variable
How does java avoid using temporary variables? Java temporary variable
How to optimize JAVA code and improve execution efficiency

Website optimization usually includes two aspects: reducing the size of code and improving the running efficiency of code. Too many articles have been written about reducing code size. Let's briefly discuss how to improve the efficiency of the code. 1. Creating an instance of a class without the new keyword When creating an instance of a class with the new keyword, all constructors in the constructor chain will be automatically called. But if an object implements the Cloneable interface, we can call its clone () method. The clone () method does not call any class constructor. When using DesignPattern, if you create an object in factory mode, it is very simple to create a new object instance by using the clone () method. Secondly, the JDK with a lower version of non-blocking I/O does not support non-blocking I/OAPI. In order to avoid I/O blocking, some applications adopt the method of creating a large number of threads (in good cases, buffer pools will be used). This technology can be seen in many applications that must support concurrent I/O streams, such as Web servers, bidding and auction applications. However, creating Java threads requires considerable overhead. JDK 1.4 introduces the non-blocking I/O library (java.nio). If your application needs an earlier version of JDK, you need a package that supports non-blocking I/O. Careful use of exceptions is harmful to performance. To throw an exception, first create a new object. The constructor of the Throwable interface calls a native method called fillInStackTrace (), which checks the stack and collects call trace information. Every time an exception is thrown, the VM must adjust the call stack because a new object will be created during processing. Exceptions can only be used for error handling and should not be used to control program flow. Four. Do not initialize variables repeatedly. By default, when calling the constructor of a class, Java will initialize the variables to some values: all objects are set to null, integer variables (byte, short, int, long) are set to 0, float and double variables are set to 0.0, and logical values are set to false. When a class is derived from another class, this should be paid special attention, because when an object is created with the new keyword, all constructors in the constructor chain will be called automatically. 5. Try to specify the last modifier of the class. Classes with the final modifier are not derivable. In the Java core API, there are many examples of applying final. For example, specifying final for the String class through java.lang.String can prevent people from overriding the length () method. In addition, if a class is designated as final, all methods of the class are final. The Java compiler will look for opportunities to inline all final methods (this is related to the specific compiler implementation). This can improve the performance by 50% on average. 6. Try to use local variables to call the method, and the passed parameters and temporary variables created in the call are saved in the stack, which is faster. Other variables, such as static variables, instance variables, etc. Is created in the heap, very slow. In addition, local variables can be further optimized according to a specific compiler /JVM. I hope to adopt them. Thank you. How to use temporary variables in C language?

Methods:-Save it in a working file, which can be saved in hard disk, USB flash drive, SD card or even the native EEPROM of PC. Every time you run the program, read back the previously saved variable value to initialize the variable. -Save it in a resident program space. As long as the power is not turned off, the running program can find the saved value in the memory after the last run. -Save on the Internet, similar to storing files on a local disk. Find the Internet address where the data is saved, or save it on a network disk.

Word file cannot be created when 07Word appears. Please change the temporary environment variable. How to solve it?

Modify the temporary folder of Internet cache for IE, and change the default path to another path 1. Open IE and select Tools->; "Internet Options", find the settings: 2. Click "Move Folder" to specify a new folder and then confirm that the problem lies in the temporary file of IE because WORD reads and writes IE's temporary folder when reading and writing documents.

How to reduce the use of global variables in C language?

In C language, you can use multi-molecular functions to reduce the transmission of variables in a large range, so as to reduce the use of global variables.

Global variables, also known as external variables, are a term in programming. Object functions define variables externally, which can be created anywhere in the program, and of course can also be referenced by programs and objects.

Variables defined in a function are internal variables, which are only valid within the scope of this function, that is to say, they can only be used within this function, and those that cannot be used outside this function are called local variables.

Therefore, in order to reduce the use of global variables, it is necessary to define all temporary variables as local variables of sub-functions.

What does it mean to use temporary variables?

Also, what do you mean the Temp variable didn't keep its function? Do you want to automatically clear the contents of the Temp variable after the PLC finishes once, or do you want to wait for the next time to change its contents just like the M variable?

How to use fb block temporary variables?

A TEMPorary variable (temp) is a variable used to temporarily store data when executing a block. These data are stored in the local data stack (L stack) in the CPU working storage area. Temporary variables can be used to organize expression OB, function FC and function block FB. They are used to temporarily store data when executing blocks. Once the block is introduced and the stack is reallocated, the data in the temporary variable will be lost.