I have a question on the wasting of the memory on the use of menus.
What is the task:
I have mainMenu, subMenu1, subMenu2, subMenu3, ...
Entry from mainMenu, and chose 1(or 2, 3,..) to subMenu1. If tasks done, go back to the mainMenu.
The Codes:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
void mainMenu(){
//input 1-3 by user
switch(choice) //choice is the input
{
case 1: subMenu1();
break;
case 2: subMenu2(); //keep simple, use two sub menus
break;
default:
//blabla...
break;
}
return; //return to main function or whatever upper level
}
void subMenu1(){
//done something
mainMenu();
}
//subMenu2 is similar to subMenu1 and has a "mainMenu()" call.
|
My problem is:
the call for mainMenu() in subMenus looks like a recursion, which means the memory would be reallocated again for the called maniMenu. Is that right?
If so, times of the memory space for mainMenu function are required if going back to mainMenu several times from subMenus. But what i wanna just a choice and I dont want to wast the memory.
How to avoid the memory cost?thanks.