| Reply | « Previous Thread | Next Thread » |
|
Hi,
In the documentation "Efficient MIDP programming", it is mentioned that using "source-code preprocessor" is better than "static final" variables. What exactly is it? How to use it? Thank you Nelson |
|
I am interesting too in using a preprocessor integrated in wtk,...
McMc |
|
Join Date: Mar 2003
Posts: 162
Location: Malaysia-Johor-Pontian Kecil
Offline
Regular Contributor
|
|
Hi,
What I guess is like that: If our MIDP suite has 2 files A and B. Inside A, we define 5 "static final" constant, inside B, we define 4 "static final". The 6 "static final" must "eat" some spaces in the .jar. How abt we create another class C? This class is ONLY used to define constants and we can move the 9 variables to C. After compiled, constants in A and B will be all replaced by the actual values from C. And then, we can remove C since C is useless in the suite. This way can save the spaces for defining constants in the A and B. I hope I don't mistake the meaning.. :) Good lucks. |
|
Hi!
Good idea ! Thanks McMc |
|
That's right... static final members are expensive on space. A pre-processor is used by C compilers to process the source code before the compiler sees it. You will see directives in C programs like:
#define MAX_ARRAY_SIZE 256 which defines a constant. The compiler itself never sees this... this directive tells the pre-processor to replace every occurance of the text "MAX_ARRAY_SIZE" within the source code with the text "256". So the source code reads: char ach [MAX_ARRAY_SIZE]; but the compiler sees: char ach [256]; (The pre-processor has enough of an understanding of C not to replace text in double-quotes, for example). So in a C program, there is no difference between a symbolic-constant (one with a name) and a literal-constant (one that just has a value). C and Java are sufficiently similar that you can get away with using a C pre-processor with a Java program. You'd need to add an appropriate command to your 'make' routine. Using the pre-processor from the GNU C compiler, that would be something like: cpp -P -nostdinc -undef MyClass.java You can also make use of other feature of the pre-processor, like conditional compilation, which allows you to include extra sections of code for a "debug build", or exclude them from a "production build". Graham. |
| grahamhughes |
| View Public Profile |
| Find all posts by grahamhughes |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|