I am aware that this is an easy problem but I don’t know how to do properly what I have in mind. I am using SFML but you don’t need to understand how it works.
Here is my simple code snippet that generate tiles and assign them to a 2D-vector of tiles:
http://www.pastie.org/2665489
During the construction of the TilePlane object, each operation (tilesMap[i]).push_back(tile) takes far too long and I feel that I am copying data instead of using a more elegant method. So in this case, what is the good method to solve this problem?
You have a lot of performance issues in your code. If the bottleneck indeed comes from
push_back, you should take Masoud’s suggestion and push pointers onto the array and not values.Another suggestion is that you declare your functions and constructors to use references – for example:
instead of
Passing the parameter by value will force a copy to be created, which can be expensive. Passing by const reference guarantees the object is not copied or modified.