performance - Java: Creating massive amount off new Objects -


i working on simple gameoflife program , try out optimizations it. problem when create cells game (small class 6 primitives) can take long time (especially when create 10000*10000 ).

so question if has idea how faster?

cells = new cell[this.collums][this.rows];  (int x = 0; x < cells.length; x++) {     (int y = 0; y < cells[0].length; y++) {         cells[x][y] = new cell(x * this.cellsize, y * this.cellsize, this.cellsize);     } } 

if you're big (or quasi-unlimited) game fields, should not model single cells objects in first place.

the field in game of life not populated much, it's better modelled sparse matrix. there huge number of trick optimize game fo life implementation - both data storage performance (copmuting field on next step). check question, instance:

sparse matrices / arrays in java

it might idea have cell instances representing single cells, , might work relatively small fields. if aim larger fields, won't work well. in case you'll have trade oo efficiency.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -