Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!newstop!west!runcible.West.Sun.COM!lwake From: lwake@runcible.West.Sun.COM (Larry Wake) Newsgroups: comp.windows.open-look Subject: Re: XView Programming Style Keywords: XView Message-ID: <1552@west.West.Sun.COM> Date: 23 Mar 91 00:06:12 GMT References: <1991Mar13.193948.16328@sol.UVic.CA> <7207@ecs.soton.ac.uk> Sender: news@west.West.Sun.COM Organization: Sun Microsystems, San Diego, CA Lines: 88 In article <7207@ecs.soton.ac.uk> mrd@ecs.soton.ac.uk (Mark Dobie) writes: >In <1991Mar13.193948.16328@sol.UVic.CA> awatkins@lager.UVic.CA (Andrew Watkins) writes: >>iI have a bunch of popup window (~7) and >>I'm adding more all the time. At present I create all of my windows >>when the program starts up and set the visibility off for all the >>windows I'm not using. Is this bad form? Should I create my windows as >>they are needed and destroy them when I'm done or does it really >>matter? > >Good question. This is how I do it too, but when I told my friend the >Microsoft Windows/Presentation Manager programmer he nearly had a >heart attack. He went on about the memory and the system resources and >stuff. I reckon this way is neater because you can do things to the >windows when they are invisible. Besides, creating the windows does seem >to take a while sometimes. In the manual "XView Version 2 Reference Manual: Converting SunView Applications," Appendix B ("Performance Hints") says: "As a rule, create resources such as pop-ups only at the time they are required." If you think about it, this makes a lot of sense. For example, in an application I'm writing there are nine windows, including the main window, with more possibly to come. However, I figure the average user will use four of those with any frequency; the other four they may never use. As Mark mentioned above, these windows will take time to create; they'll also consume X server resources and application memory. So, why create them until they're first needed? If I don't create them all at once, the program starts that much faster, and the time taken to create windows is distributed equitably throughout the total execution time of the program. I use DevGuide quite heavily; the code I write to replace the stub routines looks something like this: #include "foowin_ui.h" int foo_window_created = FALSE; foowin_frame_objects *foowin_p; /* * Representative of a function that needs window "foo" visible. */ void func_that_frobs_the_foo_window() { show_foo_window(); xv_set(foowin_p->bar_item, PANEL_VALUE, "Hi there!", NULL); xv_set(blah blah blah); } /* * How we pop up window "foo" -- makes sure it exists, first */ void show_foo_window() { if (!foo_window_created) create_foo_window(); [ Stuff to set up a window each time it pops up goes here] xv_set(foowin_p->frame, XV_SHOW, TRUE, NULL); } /* * How we create window "foo" -- the verbosely-named function is * auto-generated by DevGuide and lives in foowin_ui.c */ void create_foo_window(); { foowin_p = foowin_frame_objects_initialize(base_frame, NULL); [code to pick up stuff DevGuide misses goes here] foo_window_created = TRUE; } You can still do stuff to windows while they're not showing if you want; just put the "if (!created) create_it();" construct in any function that wants to deal with that window. -- Larry Wake, Sun Microsystems (larry.wake@west.sun.com) "Father McGrath! I thought you were dead!" "I was!"