How do you typically handle data ownership in these systems?
Right now I just have a map that maps type(std::string or hashed int)->void* where outside sources can add attributes via a simple AddAttribute method.
Right now I'm having the problem of where and how to delete some of that data, since some of it is added via outside sources (e.g. reference to another entity) and some of it is legitimate data of the entity that contains it (e.g. health attribute).
The most obvious solution would be to simply use shared pointers, but somehow I'm worried that their overhead will become noticeable when I have a lot of entities (see https://stackoverflow.com/questions/3628081/shared-ptr-horrible-speed).
Another solution that I could come up with was to first use two distinct methods: "AddAttributeExternal" and "AddAttributeInternal" (or something similar, naming is irrelevant) where the attribute would only delete data that was added via the second. But I would like to avoid this since it introduces duplicate code and can probably be error prone when you introduce a lot of changing data.
Are there better/more optimized solutions or do I need to change the way I think about entity data altogether?