Sign in to follow this  

Most memory effective way to do this

This topic is 1957 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello!

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:
[CODE]
ItemInfo* UI = new ItemInfo();
[/CODE]

And then when i want to draw something new i contact the build function in the class to update it.
[CODE]
UI->build(all the variables);
[/CODE]

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.

[b]This way the UI is basically always gonna be on the screen (in the memory), just invisible to the user most times.[/b]

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.
[CODE]
ItemInfo* UI = new ItemInfo(all the variables);
[/CODE]

Then if i don't want to show it anymore i delete the object and set the pointer to NULL
[CODE]
delete UI;
UI = NULL;
[/CODE]

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
[CODE]
ItemInfo* UI = new ItemInfo(all the variables);
[/CODE]

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)

[b]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.[/b]

Which way is more effective?

Share this post


Link to post
Share on other sites
How often will you be displaying item info? If it's reasonably often, if there is almost always some item info on-screen, and if the item for which info is being displayed changes frequently enough, then you should probably accept the extra memory overhead, otherwise you're looking at a potentially bad run-time bottleneck.

Even if not, you should definitely be profiling memory usage to determine if you are or are not worrying overmuch about something that may not even be a problem. Even if you've got a coupla extra MB usage, this is almost totally insignificant by todays standards - the days of having to be ultra-frugal about memory usage, and when memory usage was highly likely to be a major program bottleneck, are over.

That's not an excuse for going nuts or doing stupid things; it just means that focussing solely or even primarily on memory usage is not as important as it used to be.

Share this post


Link to post
Share on other sites
[quote name='mhagain' timestamp='1343912301' post='4965508']
How often will you be displaying item info? If it's reasonably often, if there is almost always some item info on-screen, and if the item for which info is being displayed changes frequently enough, then you should probably accept the extra memory overhead, otherwise you're looking at a potentially bad run-time bottleneck.

Even if not, you should definitely be profiling memory usage to determine if you are or are not worrying overmuch about something that may not even be a problem. Even if you've got a coupla extra MB usage, this is almost totally insignificant by todays standards - the days of having to be ultra-frugal about memory usage, and when memory usage was highly likely to be a major program bottleneck, are over.

That's not an excuse for going nuts or doing stupid things; it just means that focussing solely or even primarily on memory usage is not as important as it used to be.
[/quote]

Well that depends on the player. But imagine Diablo, there you look at the stats a whole lot. Or WOW, where you check your stats on items a lot as well.

[quote name='Ashaman73' timestamp='1343912558' post='4965510']
Take the first approach. Instanciate all the widgets you need and display them ,when needed. There's no reason to create/delete them all the time.
[/quote]

Guess i'm going with the first option. I were aware that it might no make any difference since like you said there is a lot more memory to work with today, but i always feel that i want to do it "the right way" with as little sloppiness as possible [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img]

Thanks for a quick reply you both! :) Edited by Tallkotten

Share this post


Link to post
Share on other sites

This topic is 1957 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this