I know it is not a good practice to use the new
command to dynamically create data, however, if I would never use the delete
, would it result in memory gaps/other problems?
Background
The reason I need to create instances dynamically, is that I want to test my application first on a PC. And I want for several classes to have more properties for the PC version than for the Arduino version (for example, to store names, or information for the PC GUI to display). The PC version classes will be inherited from the Arduino (real) classes, but with added properties.
In some classes I need to build up a list, and I cannot use a type with hardcoded values to fill an array.
Example:
I have a LightSetup class that has a list of Pars (which are LED lights):
class LightSetup
{
protected:
Par* _pars[NR_OF_PARS];
Par is the Arduino/real version, to fill in these I need:
LightSetup::LightSetup()
{
for (int n = 0; n < NR_OF_PARS; n++)
{
_pars[n] = new Par(1 + 8 * n);
}
}
In the PC version, instead of new Par, I use new TestPar. And in the header I cannot define it without a pointer like this:
Par _pars[NR_OF_PARS];
Otherwise it cannot contain TestPar instances.