Hi
I was wondering whether it is better to store something on the stack vs on the heap?
Consider the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13
struct config
{
int data = 43;
};
class Manager
{
private:
std::vector<config> configs; //on stack like this?
std::vector<std::unique_ptr<config>> configs; //or on heap like this?
public:
config& GetConfig(int index);
};
As you can see Manager has a vector of configs structs, and Manager is only ever going to be giving out references to the configs.
Would it be better to use pointers and allocate the structs on the heap?
or on the stack?