Looking for Code Criticism

Really?

Really?
Can you give me a source please? It’s not that I put your skill into question :slight_smile: , but I just can’t believe it… If it really is like that, why is that? I’ve heard about page aligning, but what exactly is it? And why is it needed?

EDIT:
I’m VERY sure my game once took much less memory (~100 mb), when I memory-optimized a class which had a [icode]private int flags;[/icode] to a [icode]private byte flags;[/icode] (Dunno about the exact number of instances, but it is my worldOfCube game, so about 10-50 million instances…)

I’m pretty sure he meant 32 bits. Anyway, Java packs fields aggressively (it sorts them by size, unlike C), but when you’re passing a short/char/byte around as an arg or storing it as a local variable, they’re going to take at least a word each.

The main reason to use a smaller type like short or byte, other than to save a little space in the object, is when you know beforehand that the range of the value will fit and you want to statically guard against narrowing conversions. Most of the time it’s just such a pain in the ass (especially byte which is signed, contrary to 99% of use cases) that most people just never bother and stick with int instead.

This blog post has a pretty good rundown on the runtime memory layout of java objects. Keep in mind none of this is in the spec, it’s implementation-dependent, and different JVMs may work differently, even different versions of the same JVM.

Sorry, my source turned out to be from 2001… And yes, I meant bits, not bytes. Dammit!

Just so that I’m following along correctly… If I use a byte or a short it should only be when the number it’s holding will stay within the limits of that data type; But I should just go ahead and use ints instead because it can be a pain to use bytes/shorts?