camelCase
The Case of the Mysterious Camel.
- Reaction score
- 362
I'm taking this module which forces us to use the Android SDK, which, "yay", is in Java. I was working on a game halfway through and realized that the frame rate was dropping as I progressed, so I ran the app through a profiler and saw that it was my Vector2 math class that was causing it.
Because I have so much math going on, I also allocate a lot of Vector2 instances.. And, because Java is Java.. It's all allocated on the heap.. Which takes up a lot of memory.. And GC causes the frame rate drop..
So, I've decided to re-write my Vector2 class so that it never creates a new Vector2 instance in any of its calculations. That's half the battle.
The second half is this:
Because I have code everywhere that needs to use vectors temporarily, I decided to have some "tmp" vector2 instances allocated. Now, all of this just means that any code using TmpX will not be thread-safe. Luckily, I don't need thread-safety.
But, say, in the future, I DO need thread-safety. Is it okay to assume that this will suffice?
If so, is thread-safety (by stuffing the synchronized keyword in there) or GC more efficient/better for frame-rate?
Because I have so much math going on, I also allocate a lot of Vector2 instances.. And, because Java is Java.. It's all allocated on the heap.. Which takes up a lot of memory.. And GC causes the frame rate drop..
So, I've decided to re-write my Vector2 class so that it never creates a new Vector2 instance in any of its calculations. That's half the battle.
The second half is this:
Code:
public class Vector2 {
public static final Vector2 TmpA = new Vector2();
public static final Vector2 TmpB = new Vector2();
public static final Vector2 TmpC = new Vector2();
public static final Vector2 TmpD = new Vector2();
public static final Vector2 TmpE = new Vector2();
}
Because I have code everywhere that needs to use vectors temporarily, I decided to have some "tmp" vector2 instances allocated. Now, all of this just means that any code using TmpX will not be thread-safe. Luckily, I don't need thread-safety.
But, say, in the future, I DO need thread-safety. Is it okay to assume that this will suffice?
Code:
public synchronized void methodThatUsesTmpX () {
Vector2 someV = Vector2.TmpA;
//More code
}
If so, is thread-safety (by stuffing the synchronized keyword in there) or GC more efficient/better for frame-rate?