C++ - Performance of vector of pointer to objects, vs performance of objects

后端 未结 3 976
别那么骄傲
别那么骄傲 2021-01-02 18:13

In this case the question scenario is a game, so all resources are allocated at the beginning then iterated over for a level.

The objects being stored in the vector

3条回答
  •  Happy的楠姐
    2021-01-02 19:02

    The first thing is pointers should be used for storing bulky things . Because if you use array of objects if would be creating n bulky objects and copy each one everytime its stored(it is also a big cost) And the second thing if you are using vectors(STL)The vectors size grows every time its gets full of memory. The main cost is copying the data of first in second and this is actually the main cost i.e copying. Also this cost is minimal cost that would be incured if use built in.

提交回复
热议问题