Cuttin’ Up
March 12, 2009 Uncategorized 1 Comment

Alright, installment two of our clipboard cache project.
This whole project centers around the clipboard. So what a great place to start!
We are at a disadvantage. Arggg, already negative! I should explain. Microsoft has some built in features that would make this project easier. For windows, we could add our application into a chain of other applications that are all notified when any action happens regarding the clipboard. This would include copying text into the clipboard, which is exactly what we are going to need to watch out for. However, since we are trying to develop a platform independent application (and we’re not developing in .NET), we don’t have access to this functionality. Cripes. What is the answer? Busy waiting. <Game show Fail sound here…> Wa..wa..wa….
Ah, a chance for an aside: “busy waiting”, or “polling” is a concept in computer science that is a nice way of saying bug the thing that you want to get something from until you get it.
An illustration would fit great here. Let’s say that you are on a long car ride, and you have a five year old child in the back seat. The child, of course, does not want to interrupt the operation of the vehicle, or distract you the driver in any way, however, they also want to know when they have arrived where they are going. Naturally, the answer to this dilemma is an event based architecture. The child says, before the car even starts moving no less: “Father, please inform me when we have reached our final destination. I will play quietly with my GI Joes until you have instructed me to do otherwise.” The event of arriving at where you are going causes the child to be informed of something that is meaningful to them. What a perfect world of family vacation bliss! Any of you out there with children know that this is seldom (uh, try never) true to real life. How about this scenario instead:
Car in driveway.
Child- “Yeah! Vacation!”
You - “Yeah!”
Car pulls onto street in front of house.
Child- “I’m bored!”
You - “Play with the new GI Joe I just bought you.”
Car pulls out onto main road.
Child - “How long is this going to take?”
You - “How about I just let you know when we are close…”
Car merges onto freeway.
Child - “Are we there yet?!?!”
You - “no”
Every other step of the way - “Are we there yet?!?!”
You - “no”
…
Child - “Are we there yet?!?!”
You - “I will pull this car right around and take us home if you don’t stop asking me that!!!”
That my friends, is busy waiting. Thankfully, computers are much more patient that we are, so they don’t mind when we ask them the same question repeatedly. One very important thing to consider though, is that a computer is not like an annoyed, although loving parent. They are more like a taxi cab driver. You can ask as many questions as you want, and they will still happily take you to where you are going - if we can pay there fare. The fare in this case is that we have to use resources (namely performance-expensive CPU cycles) to perform the busy waiting.
So with that, it brings us to our application model- we are going to have to ask the clipboard constantly if it has changed or not. Annoying, but necessary for what we want to do. Well, lets pay the piper, and get started a-coding!






