View Full Version : Which is more efficient?

02-07-2008, 10:55 PM
I was reading the other thread about the news thing...
Anyways, which is more efficient, letting a GUI be closed(and destroyed) and recreating it whenever it's needed or having it hide on being closed, and simply showing it when needed?
I'm asking because I'm not sure how exactly GUI's are handled and if having one destroyed is quite the same as one that's not visible. So I guess this is a question for those a bit in the knowing about the behind-the-scenes stuff.

02-07-2008, 11:04 PM
Well, storing it won't take CPU, but memory.

Destroying it and then recreating it would take CPU but in spikes.

02-07-2008, 11:30 PM
I always use the destroy/recreate method when I'm working on it....then just forget to take it out ^^

02-07-2008, 11:52 PM
I'm not so sure, either. I normally just create them then change the visible flag. I believe the scripted RC does this also.

02-08-2008, 12:10 AM
I'm not so sure, either. I normally just create them then change the visible flag. I believe the scripted RC does this also.
The Scripted RC's main window with RC chat is created when you first start to use it, hidden when you use the X button or F6, rather than destroyed, and brought back as needed. All of the other windows are destroyed, and are recreated as necessary.

02-08-2008, 12:29 AM
You can notice that all of the default built-in guis are never destroyed but are in fact hidden.

02-08-2008, 01:07 AM
It usually depends for me. If it's a Gui that can change a lot, I generally don't destroy it, so I won't have to use a lot of processing bringing it back. Otherwise I do destroy and recreate it.

02-08-2008, 02:31 AM
If you hide it and show it again later then the position and size are the same, which is often better than recreating it and the user needs to move it again if it's not at the good place. You can use showtop() to make the window appear on top, un-minimize and get the input focus.
Normally creating and hiding windows is not a big problem, they might take a few kbytes in memory but should not be a speed problem. There are many default windows (playerlist, F5, F2 etc.) which are created in invisible state when you login to the login server. For stuff like PM windows it needs to create new windows of course, and is then also destroying them when you close them.
So I would say if you only need the window one time then destroy it afterwards, and if you plan to open it several times then just hide and reopen it next time.

02-08-2008, 08:47 AM
Exactly. For something like an inventory or a player chat system, you should most likely just be hiding/showing it. Something that creates a separate GUI for each instance should just be created/destroyed.

I also sometimes go in the middle and show/hide a main gui but destroy its contents for GUIs that are ambiguous.