In my case, is using Java preprocessor bad?

T

Taeyun Kim

I'm a (relatively novice) java programmer for mobile devices.
In that environment, the size of java classes really matters. (Not the
JARed format; the size when the class is loaded into memory is
important.)
Here is a problem: A public static final member variable definition
costs 31 bytes in non-JARed class file. And it affects the memory
profile of the running program. And I have several hundreds of the
constant variables. So, I can't help prefering the use of #define
constants to the use of public static final member variable.
Is there any better method?
 
B

Boudewijn Dijkstra

Taeyun Kim said:
I'm a (relatively novice) java programmer for mobile devices.
In that environment, the size of java classes really matters. (Not the
JARed format; the size when the class is loaded into memory is
important.)
Here is a problem: A public static final member variable definition
costs 31 bytes in non-JARed class file. And it affects the memory
profile of the running program. And I have several hundreds of the
constant variables. So, I can't help prefering the use of #define
constants to the use of public static final member variable.
Is there any better method?

Better method: get a smarter compiler.
 
C

Chris Uppal

Boudewijn said:
[..] the size when the class is loaded into memory is
important.)
Here is a problem: A public static final member variable definition
costs 31 bytes in non-JARed class file. And it affects the memory
profile of the running program. And I have several hundreds of the
constant variables. So, I can't help prefering the use of #define
constants to the use of public static final member variable.
Is there any better method?

Better method: get a smarter compiler.

It's nothing to do with the compiler, it had to include the definition of the
"constants" or else it won't be a Java compiler.

To the OP. There are several tools that will strip unused crud out of compiled
classfiles (I can't remember names off-hand, but your favourite search engine
should know if no-one else mentions them here). It might be worthwhile looking
into that option, since there's a good chance that they'd save more than just
the memory for the constants.

Failing that, I'd use a pre-processor and to hell with it ;-) (BTW, if you are
carefull you can arrange it so that the souce would still be correct Java even
if you didn't use the pre-processor, which would be worth a little extra effort
IMO)

-- chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top