I'm in need of help. I am about to build a system that displays info about an item on the screen and i need some help to understand which of 2 ways is the most memory effective.
So basically in my game i am making there are items on the ground. If the player holds down CTRL he/she gets up an UI that draws out the stats and name of the item.
I currently got a sloppy but functional system and i want to improve it. I got 2 ways in mind.
First way:
First create a object of the class in the initiation:
ItemInfo* UI = new ItemInfo();
And then when i want to draw something new i contact the build function in the class to update it.
UI->build(all the variables);
When i want to show it i switches a bool which makes it draw on the screen. I switch the bool to false when i want to hide it.
This way the UI is basically always gonna be on the screen (in the memory), just invisible to the user most times.
Second way:
When i want to draw the UI i create a new object of the class and sends all the necessary variables with it.
ItemInfo* UI = new ItemInfo(all the variables);
Then if i don't want to show it anymore i delete the object and set the pointer to NULL
delete UI; UI = NULL;
If i want to show it again/update it i recreate it again, but with different variables. Of course if it isn't deleted already i have to do that first
ItemInfo* UI = new ItemInfo(all the variables);
I show it if the pointer != NULL, if it is NULL I don't try to draw it (since there isn't anything to draw)
This way is more memory and CPU intense when i am showing itemInfo but the memory is freed when i ain't doing anything with it.
Which way is more effective?






