Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!usc!apple!agate!ucbvax!ucdavis!csusac!unify!openlook!openlook-request From: rick@pbi.com (Richard M. Goldstein) Newsgroups: comp.windows.open-look Subject: Re: XView Programming Style Message-ID: <0x6u9ws@openlook.Unify.Com> Date: 26 Mar 91 12:59:38 GMT Lines: 76 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? a great topic! one that is certainly relevant. 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. my applications have a bad case of this too, so i've been thinking on this. 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); } so far, i'm down with ya..... 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) somehow, i still don't think most applications of any sophistication would get all the way through their setup with this technique, they would still end up creating everything between invocation and the call to xv_main_loop(). a more sophisticated technique would be to create an "object" (i.e. structure) that represents all of the controls on the popup and interact with the popup through this object. this way, at invocation you would malloc() the structures and maintain a coherent "state" for the popup by getting/putting values into the structure. then, on down the road when the user selects this popup off the menu, call to the devguide initializer and copy the contents of the corresponding structure into the popup and then set XV_SHOW to true. granted this takes more work, but it allows you to keep things coherent while still postphoning the window creation until absolutly necessary. I'd certainly like to hear if anyone has any better ideas. rick %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % Richard M. Goldstein % % % % Perfect Byte, Inc. Phone: (402)554-1122 % % 7121 Cass St. Fax: (402)554-1938 % % Omaha, NE 68132 email: rick@pbi.com % % % % "If I knew what I was doing, % % d'ya think I'd be in Omaha?" % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%