Lets say you make a game engine, and you have several GameObjects and every GameObject have a list of components that you can add or remove.
Lets say there is a MeshComponent who has vertices, normals etc. If several GameObjects have the same MeshComponent, there will be a lot of memory waste. Of course there are many ways to implements this but I want some good advice how to solve this? How do components share data that is not going to be modified?
C++ does not have static classes.
If several
GameObjectshave the sameMeshComponent, there will be NO memory waste.Because, of course, it is the same
MeshComponent…You will waste memory if you have many copies of the
MeshComponentwhich conceptually should be identical.If many
GameObjectsneed to refer to the sameMeshComponentthen they should each hold a (smart) pointer to the sameMeshComponent.