I'm developing a android game and i have a question about storing the game elements without firing garbage collector.
My game needs a collection where the game elements are stored according to x,y positions (all game elements have x,y,width and height). The collection is then called every frame to retrive the elements according to cameraX,cameraY,camera width and height (user can scroll around the game).
Example:
function draw() {
tmp = collection.getElements(tmp,cameraX,cameraY,cameraWidth,cameraHeight);
for(int i = 0; i < tmp.size(); i++) {
tmp.get(i).draw();
}
}
I'm currently using the Vector class to represent the collection elements, but the gc keeps firing every couple of minutes. I do all my allocations up front. I've also modified the getElements function to accept 1 more parameter - a temp vector(allocated upfront) which is filled with elements and then returned.
- With which class to store the game elements so the gc wont fire (i prefer never if possible)?
- i also add elements to the collection during runtime, do i have to allocate them upfront also?
Thanks,
Regards J.