Matt-and-Gib / gleemail

glEEmail is a novel hardware/software peer-to-peer chat application for Arduino
The Unlicense
0 stars 0 forks source link

Separate constructor logic into "init" or "begin" functions #84

Open AVividLight opened 2 years ago

AVividLight commented 2 years ago

Right now, our objects use their constructors to do initialization. This is good C++. It can be bad Arduino code, though; constructors for global-namespace-objects (which we're trying to move away from) are called before main(), meaning bugs in them can fault the Arduino before it begins.

Also (and admittedly, this is my primary reason), if we separate an object's setup from it's creation, we can allocate them on the stack in main and call their "init" or "begin" from our setup function.

One downside which MUST be thoroughly considered before we embark on this is thus: we cannot delete/free stack memory, so if a user isn't using Storage (for example), we will not be able to recapture that memory (whereas now we can delete Storage if no SD card is detected). I don't know if there's much we could do with that extra memory, but let's make sure that this trade-off is worth it.