Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Stuck with Lazy Loading - A Transitive Reference Puzzle

Stuck with Lazy Loading - A Transitive Reference Puzzle
Thread Tools
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status: Offline
Reply With Quote
Jun 18, 2001, 10:55 PM
 
Along with the recent Development Tools update came a nice example that shows how to lazy load multiple nibs - SimpleMultiWindow. By lazy load I mean one window loads the next window upon the ocurrance of some event in the first window.
For example do something in W1 and it loads W2; similarly, do something in W2 and W2 loads W3 etc.

Inspired by Apples 2 window example I created a program that has 3 windows each lazy loaded from 3 different nibs; each window has one text field and one button. The main purpose of the button is simply to broadcast a text message to all other text fields except for the one associated with window that genereated the event.

The problem that I run into is that because of lazy loading the last window loaded (say W3) has a reference to the instance that created it (say W2) but it has NO reference to the specific instance that loaded W2 (say W1) and therefore W3 can't send a message to W1. How does W3 reference the specific instance of W1 that created W2?

This must have a simple solution. Any ideas?


[ 06-19-2001: Message edited by: DaGuy ]
iMac 17" G4 800MHZ & 768 SDRAM
     
Mac Enthusiast
Join Date: Feb 2000
Location: Storrs,Connecticut, USA
Status: Offline
Reply With Quote
Jun 19, 2001, 07:18 AM
 
Okay, so some object associated with your last window can see your second to last window but not your first window and you want all of the windows to receive a common message. That's what notifications are for. Just make all of your windows observers for some type of notification with a certain name, but any object. When they get the notification have them check to see if they are the one that sent it. If they are, then just have the function immediately return, otherwise have it do whatever you want it to do.
     
DaGuy  (op)
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status: Offline
Reply With Quote
Jun 19, 2001, 08:09 AM
 
Cool, thanks for your message. I suspected that it had to be something straightforward like notifications. Now, just for fun, lets say we do not want to use notifications. What other techniques can we use to detect objects? Say we had a population of objects with new ones being born every second, what is the most efficient way of making all other objects aware of the newborns?

You see what I am worried about is that notifications may add much overhead and hence loose performance. I figure that if an object is listening for something to happen then it assumes some (perhaps non trivial) performance cost. What do you think?


iMac 17" G4 800MHZ & 768 SDRAM
     
Fresh-Faced Recruit
Join Date: Sep 2000
Status: Offline
Reply With Quote
Jun 19, 2001, 08:23 AM
 
The problem that I run into is that because of lazy loading the last window loaded (say W3) has a reference to the instance that created it (say W2) but it has NO reference to the specific instance that loaded W2 (say W1) and therefore W3 can't send a message to W1. How does W3 reference the specific instance of W1 that created W2?
Is this always going to be a 3 window app? If so the answer seems pretty straightforward... In your given example, after W2 loads W3, it could send a message which sets W3's third window member variable equal to its (W2's) own parent, which would in the example given be W1.

Or your controller class could hold references to each window, and when a window's awakeFromNib method is called, it (the window) sends a message to the controller telling it to go through it (the controllers) list of windows, and update each one's list of targets.

Anyway, I think either of those work, for a simple app such as you describe. Notification is also a good method, I'd say, and possibly less cluttered.
     
DaGuy  (op)
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status: Offline
Reply With Quote
Jun 19, 2001, 10:53 AM
 
Thanks! I am not planning on fixing the number of windows. So I guess the notification mechanism is likely the best way to go. But as I mention above, I wonder what the performance penalty is? Performance is really what this experiment is about -by lazy loading the number of launch time bounces is reduced considerably. Be as it may, thanks for the good suggestions.
iMac 17" G4 800MHZ & 768 SDRAM
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:22 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2