I have a struct for a menu system that im trying to modify to reduce memory usage, but i cant figure out a good solution. Basically it looks like this:
struct menu
{
uint8 str[MAX_STR];
uint (*func)( uint8 index );
uint index;
menu *prev_ptr;
struct menu *submenu_list[MAX_MENUS];
};
The problem is that all menu items have the submenu_list even if they dont have any submenus. Im trying to find out a way to have it more dynamically allocated instead of an array of always length MAX_MENUS. Is there an obvious solution here or will i need to revamp the whole menu system
One idea was to have a single pointer in the menu struct pointing to an array of the submenus, but i haven’t gotten it to work.
struct menu
{
uint8 str[MAX_STR];
uint (*func)( uint8 index );
uint index;
menu *prev_ptr;
struct menu *submenu_list;
};
and then when initializing a menu like this
menu *submenus_main[] = { &submenu1, &submenu2, &submenu3, &submenu4, &submenu5, 0};
static menu main_menu = { "Main Menu", 0, 0, 0, &submenus_main };
Lussmar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.