4 ms·
FTA: "A quick look at the output from ddms shows I was allocating tens of thousands of Colour, Vector2 and Vector3 objects per image" And this is the fault of
by ajross 14y ago
FTA: "A quick look at the output from ddms shows I was allocating tens of thousands of Colour, Vector2 and Vector3 objects per image"
And this is the fault of the garbage collector? Doing per-primitive ops by allocating heap blocks is a disaster, sorry. No one doing HPC does that. This won't run well anywhere, though obviously a desktop machine is going to give you a lot more freedom before you see frame rate problems.
- kevingadd 14y agoIt's the fault of the garbage collector because the JVM provides no sane alternative (like, say, structs, or packed object arrays...). If there's Only One Way To Do It, that One Way should not cause the garbage collector to fall over and choke. It sounds like the desktop JVM handles it just fine, in comparison.
- ajross 14y agoWhich is one reason that no one does HPC (or related tasks, like image processing) in Java. To be fair: Android has a nifty NDK that works very well for tasks like this.
- soc88 14y agoCould you please tell me in which alternative reality you live in? :-)
- ww520 14y agoWhy not just pre-allocate the objects and reuse them?
- mwd_ 14y agoThis is what I do for Android games -- design things to be mutable and pre-allocate however many I'll need during a level. You also have to avoid foreach because it creates objects. This is an area where C# is better. You can create classes or structs and structs go on the stack. Structs are a lot more appropriate for objects like rects.
- kevingadd 14y agoHave fun getting that pattern right by hand. The language isn't doing anything to help you. Make sure you release the instances back to the pool on every exit path, but don't release them if you let a reference escape into another scope. Have fun debugging the issues that crop up when you accidentally release an instance that's still being used back into the pool. Have fun hunting down that one code path that isn't returning instances to the pool, and as a result is draining the pool down to 0 and causing you to gain nothing from it.
- ww520 14y agoDidn't people do all that before the advent of GC? People seemed to manage resources just fine.
- astrodust 14y agoIn garbage collected languages you really need to keep track of how much garbage you create. I've seen too many examples of people creating objects they really don't need in loops when they could recycle a single one for the entire procedure.