I'm writing a game for android platform. I have bullets in ConcurrentHashMap and im checking for collisions. All works great but GC is running every 3-5 seconds, when checking with Allocation Tracker there are lots of allocations ( 开发者_运维问答90 % of them ), every with allocation size = 36 in java.util.concurrent.ConcurrentHashMap$ValueIterator
Concurrency is the key because a lot of thing may happen to the bullets and normal arraylist throwed concurrent exception so i've switched to ConcurrentHashMap. How can i optimize it for speed and GC ?
for (IWeaponBullet xbullet : PlayerSystem.aEnemiesBulletsArray.values()) {
//checking
}
I think you might be calling this iteration too often. values()
call is creating a collection and gives new ValueIterator()
each time you start this for loop.
Can you cache these values maybe for longer period of times instead of executing the loop too often?
精彩评论