Reduce memory use

* Command definition now uses char * instead of String
 * registered_commands is now an array of pointers to Commands,
   previously this was an array of Command and was allocated to
   MAX_COMMANDS entries which were then overwritten with the module
   provided Commands, so every Command used twice as much memory. This
   saves ~200bytes
 * Several (u)ints are now (u)int8_t

On the nano with all modules included this reduces global RAM use from
1676 bytes to 1237 bytes (from 81.8% to 60.4%).
This commit is contained in:
Filip Ayazi 2021-07-11 05:21:38 +01:00
parent 2dab1008dc
commit 1c8e725282
4 changed files with 36 additions and 30 deletions

View file

@ -11,14 +11,18 @@
{ \
"", NULL \
}
#define CHECK_END_COMMAND(C) C.command.length() > 0
#define CHECK_END_COMMAND(C) check_end_command(C)
struct Command
{
String command;
const char * command;
void (*run)(String);
};
inline bool check_end_command(Command c) { return strlen(c.command) > 0; }
inline bool check_end_command(Command * c) {return strlen(c->command) > 0; }
const Command end_command = END_COMMAND;
uint8_t parse_arguments(char ** arguments, String, uint8_t);
extern void register_module(const Command commands[], void (*loop_fn)(void));