NamTThai / PokemonShowdownAndroidClient

Other
44 stars 14 forks source link

Annoucement: about using enum #57

Closed NamTThai closed 9 years ago

NamTThai commented 9 years ago

It recently came to my attention that Android advices against using enum. I'll be in the progress of phasing out enum. When you see enum, plz do me a favor and change all of them to public final static int

CLEMENTINATOR commented 9 years ago

What is the problem with enums?

Should I just change one enum containing X values into a class containing X public final static ints?

On 12 December 2014 at 01:33, Nam Thai notifications@github.com wrote:

It recently came to my attention that Android advices against using enum. I'll be in the progress of phasing out enum. When you see enum, plz do me a favor and change all of them to public final static int

— Reply to this email directly or view it on GitHub https://github.com/NamTThai/PokemonShowdownAndroidClient/issues/57.

BOUVET Clément bouvetcl@gmail.com (+33) 6 32 66 03 06

Lazloz commented 9 years ago

Well. The only advise I've seen regarding enums is, that they add a memory overhead. Just like any class it adds 500 byte of memory usage and every instance something 12 bytish (see: http://developer.android.com/training/articles/memory.html#Overhead for more) while an integer is 4 byte (32bit). If you want to avoid that memory usage (which imo is negligible as we aren't using that many enum constants and enums add a lot of readability) you should put the constants in a class, where they are actually used and accessed instead of creating a new one.

CLEMENTINATOR commented 9 years ago

Thanks for the explaination. I'll remove the enums i have.

On 12 December 2014 at 14:34, Lazloz notifications@github.com wrote:

Well. The only advise I've seen regarding enums is, that they add a memory overhead. Just like any class it adds 500 byte of memory usage and every instance something 12 bytish (see: http://developer.android.com/training/articles/memory.html#Overhead for more) while an integer is 4 byte (32bit). If you want to avoid that memory usage (which imo is negligible as we aren't using that many enum constants and enums add a lot of readability) you should put the constants in a class, where they are actually used and accessed instead of creating a new one.

— Reply to this email directly or view it on GitHub https://github.com/NamTThai/PokemonShowdownAndroidClient/issues/57#issuecomment-66772818 .

BOUVET Clément bouvetcl@gmail.com (+33) 6 32 66 03 06

NamTThai commented 9 years ago

@Lazloz about our memory usage, it's actually quite dramatic. I was playing around with memory analyzers over the last couple days and our memory overhead is currently around 25% of total memory usage. Also, about PokemonInfo, all changes to PokemonInfo needs to happen during animation (either onAnimationStart or onAnimationEnd), well except for those commands who doesn't have animation.

NamTThai commented 9 years ago

I'll probably need to translate all the raw resources we are having right now into value resources. That can be a next mini project.