- Balance between performance and resource occupation
Translator Note: I haven't intended to translate this article, but when I started the code and bug fix, I found out the problem in the program code. So I translated this article. For everyone Reference, where the translation mistakes are also asked, please advise. Thank you!
SUMMARY: Since the birth of the computer, in order to avoid waste of these useful resources, software performance and resource consumption, it is always a problem, and it may sometimes sacrifice some software performance to achieve this. This topic explores a method of reducing memory consumption by delaying the creation of objects to the system in Java programming. (2400 words)
When the memory on the 8-bit computer motherboard is from 8KB to 64kB, we are exciting at the moment, it seems that it will happen to see the resource we use now, and it is still increasing application system. System procedures that have been able to write to those poor memory in the past can be surprised. Although we have more memory resources now, we can learn a lot of valuable experience from the technologies based on many constraints.
In addition, Java programming is not only written some Applets and applications deployed to your PC or workstation. It has inserted into the market area of embedded systems. The memory resources and computing power of the current embedded system are still very limited. Therefore, many old problems faced in the past have reappeared in front of the Java programmer involved in the field of embedded equipment.
Balance resource and performance These factors are a very exciting design topic: in the design and development of embedded systems, no solution is perfect. We must accept this fact. Therefore, we need to understand some technical types, which is to make a better technique that the balance we mentioned above is in an existing deployment platform.
Among them, an effective technology that avoids memory consumption is passive instantiation, and Java programmers have found a useful place in actual work. Using passive instantification technology, the program will create him when certain resources are first used. --- This is equivalent to released useful memory space. In this topic, we explore passive instantiated technologies in two aspects of the creation of class loads and objects, and we have special considerations for the case of single case mode. These materials come from my work Java actual combat: The ninth chapter in Design Styles & IDioms for Effective Java.
Active initialization and passive initialization: an example
If you are familiar with the Netscapse web browser and have used 3.x and 4.x. Then you must notice that the Java runtime mechanism is different at the time of loading. When Netscape 3.0 is started, if you pay attention to the flash screen, you will find that he is loading various resources, including Java. However, in Netscape 4.x, the browser does not load the Java runtime mechanism - - It will not be loaded until you run the web page including the