First consider how much effort you want to expend on this. Modern MIDP/CLDC devices have far more memory than the original specifications envisaged. If you must reduce memory size, bear in mind that all the following techniques will reduce the readability and manageability of your code. In no particular order...
* Don't create separate classes to act as event listeners - use a class that already exists. For example, use your MIDlet's main class as the event listener for form events, rather than creating a separate class. Remember that even the most trivial, anonymous inner class requires 200 bytes of bytecode, plus some state information for each instance.
* Where possible, use ordinary named classes, not inner classes. It is conventional in AWT programming to use inner classes to act as event listeners. The state information required to support an instance of an inner class can be surprisingly extensive, because of the way that inner classes are managed by the JVM.
* Don't subclass the built-in classes unless you have to. For example, you could create a subclass of Form to serve as your applications main user interface, but you could also use an ordinary Form object, and drive it from the MIDlet's main class. Subclassing Form is more `OO', but imposes adds a few hundred bytes to the footprint. Every class you subclass has the same effect.
* Don't subclass your own classes unless you have to. The flatter your class hierarchy, the few the classes; the fewer the classes, the smaller the bytecode.
* Don't put your classes into packages. J2ME applications are self-contained, so there is no prospect for name clashes between applications. The packages names have to be stored in the bytecode, on every occasion that a class is defined or referenced. A better solution than de-packaging all your code is to use a software tool to do it. Bytecode obfuscators do this as part of their normal operation.
* Remember that array initialisations translate into lots of repeated bytecode operations. So initializing an array of month names like this:
String[] months = {"January", "February"...
* generates a surprising amount of bytecode. If you have very large arrays of strings or numbers, it generates less bytecode to define it in a long, delimited String, and split it into individual values in a loop. This may seem mad, but it's true.
* If you have to support multiple locales, plan on distributing different versions of the application for different locales, rather than supporting multiple locales in the same application. There's no point providing a load of French and Japanese text if the user wants to see only Italian.
* If an application creates a Java instance, and knows that it is no longer required, it should re-use if with different data, or set it to null. Re-use is the preferred option, where this is practicable, but setting to null will help the garbage collector determine which objects are out of scope.
分享到:
相关推荐
A subsequent update to the library to reduce the memory footprint for processing large TIFF files has been named version 4.1. The actual version when officially released may be different.
Provides a clear view of the growing footprint of web applications Explores the foundations of secure web application development and the risk management process Delves into tactical web application ...
Our e.MMC-Based MCPs do more than meet the memory requirements of mid-tier phones, tablets, auto infotainment systems and smart watches. They save more than 40% space versus discrete memory—reducing ...
The Brand Footprint品牌印记.doc
we determine the merit of traditional solutions in a main-memory context and suggest solutions which are ideally suited to the changed environment. In the first part of this thesis, the optimal ...
Memory footprint of peripheral drivers Examples Document tabsheets description: "Modules" : Lists the different modules that compose this Library. "Data Structures": Lists the variables, defines,...
The result is a highly portable, small-footprint application development environment that brings the unique capabilities of Java technology, including platform independence and enhanced security, to ...
On embedded systems, understanding arrays is critical to getting the best performance and smallest memory footprint out of applications, and hence to improving the user experience. RArray and its ...
Analyzes the main components of the FreeRTOS Application Programming Interface (API), detailing the implementation of key operating system concepts Discusses advanced topics such as formal ...
fulfill, like FIPA interoperability, small memory footprint, cost, and security. For selected agent platforms – JADE, FIPA-OS, ZEUS and JACK – we present the results of benchmarking aimed at the ...
Tuning the Java HotSpot VM for startup, memory footprint, response time, and latency Determining when Java applications require rework to meet performance goals Systematically profiling and tuning ...
Reduce the Server’s Footprint 177 Secure the Web Root 179 Securing SQL Server 187 Install or Upgrade to the Latest Version 187 Secure Microsoft SQL Server 200 Wrapping It Up 205 Chapter 13 Securing ...
His archaeology of the operational formation of machine learning does not unearth the footprint of a strategic monolith but reveals the local tributaries of force that feed into the generalization ...
Ø Tuning the Java HotSpot VM for startup, memory footprint, response time, and latency Ø Determining when Java applications require rework to meet performance goals Ø Systematically profiling and ...
Tuning the Java HotSpot VM for startup, memory footprint, response time, and latency Determining when Java applications require rework to meet performance goals Systematically profiling and tuning ...
into this "container" area and reduce the size of this "container" as necessary. If larger extensions are added or the "container" area is filled entirely, then reading and re-writing the entire ...
Windows programmers interested in writing or porting an existing Windows application, and even developers of managed code can use the information in this book to make their tasks easier. <br>The ...
Using step–by–step instruction backed by real–world scenarios, this book takes you under the hood of this powerful VMware suite, clearly explaining all of the components and how you can get the ...
Scalable: The memory footprint of µC/FS can be adjusted at compile-time based on the features you need and the desired level of run-time argument checking. For applications with limited RAM, features...
An application should maintain the consistency of a database. For example, if you defer constraint checking, it is your responsibility to ensure that the database is consistent. Isolation Concurrent ...