Friday, August 10, 2012

Virtual Stuff

.
When you play a videogame, you’re immersed in a ‘world’; you’re looking into the screen, and it is as if you were really there.

Sort of.

Something a little different, but with some common elements, was how computing was done in the sixties: this was before individual PCs.  The idea of having a complete computer all at one’s own disposal was completely alien to our minds (since back then a computer could cost up to $100,000, and a house cost only about $20,000).  Right up until about 1960, a computer indeed was at the disposal of a single individual; you had to reserve time on the thing in advance, and then you would show up at the appointed time, use the computer for your allotted 30 minutes, and go home.

Then someone came up with an operating system that could do something amazing: it could handle up to, e.g., 10 users.  Each user would be given a fraction of a second of computer time, in strict rotation.  But the users were switched in and out so smoothly, each one felt as if the computer was giving him or her its undivided attention.  So the users were virtually in control of the ‘entire’ computer for as long as he or she wanted.  (Unless, of course, there was an 11th user who was getting impatient to get on.)

Think of what the computer had to do to accomplish this: it’s dealing with user A.  Now A’s time is up, so the computer has to (1) put all of A’s program states somewhere on the hard drive, which the computer labels “A’s stuff; do not touch,” (2) loads up B’s stuff from where it had put it before, (3) restores all B’s programs to the exact place(s) where it/they had been before, and resumes talking to B.  This is called Time-Sharing, a phrase that is used in many different contexts with different meanings, e.g. real estate.  It is a very specific instance of multi-tasking, which we’re all familiar with.

This is just a simplification; imagine the details the computer has to take care of!  But this is the genius of computer programming: you only have to think of every eventuality just once, code it in, and it’s never going to be forgotten.  Actually, you don’t have to do it all yourself; eventually someone will notice something more you could do, or something you can do better, and you put that in in your next version.

What does a user need, to feel in control of the entire computer?
* access to the operating system.  There must be a keyboard and a mouse, basically, and...
* a monitor, so that you can see what you typed, and the computer gets to talk back to you,
* a printer, in case you need hardcopy of something; and in these modern times,
* an Internet connection.
When a computer is time-sharing, all these resources are swapped in and out.  Each user gets his or her individual keyboard (and mouse) and monitor, of course, but the other resources have to be rotated.  Many of my readers are probably familiar with printer queues, which is how the printing services were rotated among several users; your print job simply waited in the queue in the order in which it was sent to the printer, and gets printed out when it gets to the top of the queue.

In certain very sophisticated video games, and so-called massively multiple-player games (mmpg), each user has a head-set consisting of video glasses and headphones, and each player has in his hand(s) a gadget or a glove, which (1) gives the user the feel of whatever he or she is holding, e.g. a light saber, or a sword, or, ugh, a machine-gun, and (2) sends the direction and control-signals of the glove into the computer, to be transmitted to the game program.  You are immersed in the game in a very intense way, because most of your senses, namely sight, sound, and touch from your hands, at least, are channeled via the computer.

Another example popped into my mind, namely flight simulators that are used to teach pilots to fly, without the liabilities of actual in-air experience.  Many video games for teenagers involve driving virtual cars in a high-speed chase through a virtual city, for instance.

One of the most interesting applications of this concept of virtuality is actually in programming.  Suppose you’re a PC person, but your wife has just bought a $10,000 super-powerful Apple ® workstation.  All this while, she has been using your version of some software which is not available for Macs.  And she absolutely has to have it on her brand new, water-cooled, nuclear-powered Mac.

There are what are called Virtual Machines that can run on various operating systems.  In the present instance, there is an application called something like virtual PC, which emulates a PC right inside your wife’s new Mac.  It is a program that maintains the following:
(1) It uses a portion of the Mac memory, and maintains it as though it were the memory of a PC.
(2) It sets aside a modest file on the hard drive of the Mac, and manages it as though it were the hard drive of a small PC.
(3) It grabs input from the Mac keyboard, and responds to it as if it were a PC.  For instance, it can read a CD software disk, and pretend that it is a PC, and install the software, right on your Mac hard drive portion which it was pretending was a PC hard drive, and then proceeds to run it.  It can even register it on the internet.
(4) When your program wants to print, the virtual PC intercepts the printer signals, converts them into the signals that your Mac printer is accustomed to expecting, and your Mac printer prints it.

[Added later:

A few months ago, I installed a virtual Linux computer inside my PC!  Yes, I did, naughty me.  (Actually, this is one of the few instances where nobody cares that you do this.)  I could install a virtual printer--which, of course, printed off the regular printer that I had; the virtual computer interpolated between the Linux output, and the output my printer was expecting, etc, etc.

One of the most interesting things was getting on the Internet.  The imaginary Linux machine had to negotiate with the real PC which was  “hosting” it for access to the Internet.

Lastly, the virtual computer had to add the host computer as an external drive, can you believe it?  That was the only way to pass files back and forth.  The usual way is to mail the files back and forth.  Mailing takes care of the fact that file formats are different in the two systems.  (Actually, they’re the same, but the virtual operating system pretends that they’re different.  And there’s nothing we can do about dispelling this illusion that won’t screw up the emulation, other than, of course, passing files the approved way: pretending that one computer is a hard drive on the other.

When I ran out of space on the PC, I went into investigative mode, and found out that my virtual computer occupies quite a lot of space on my hard drive.  It occupied as much space as the installation CD and virtual hard drive combined, in addition to the size of the virtual machine software.
]

Obviously a lot of effort is going into running interference between the Mac input-channels: the keyboard, the mouse, etc, and the virtual PC inside the Mac, and in the opposite direction, intercepting PC output from the virtual PC, and converting them into equivalent Mac output-streams.  But this sort of thing has been fine-tuned over the years, and is very well understood.

In fact, in recent Windows operating systems, many programs run inside their own little private virtual machines.  Minimal virtual machines were implemented back by Windows Xp, resulting in allowing one program to crash, while the other programs kept going.  In the bad old days, if one program crashed--which meant that the program was finding itself having to respond to a program state that was not anticipated--the whole computer crashed.  You probably noticed this slight improvement in crash-handling, and never connected it with the idea of virtual worlds.

How efficient are these virtual machines, really?  On the one hand, a Mac providing a fake PC environment is working a little harder than a simple PC just being itself.  But a powerful Mac emulating a modest little PC could be expected to do very well.  Don’t misunderstand: PC’s can emulate Macs just about as well as the other way round.  Most of all, open-source Linux systems emulate both PCs and Macs all the time.  Virtual machines are here to stay.

Finally, many new software environments are written to run always in their own virtual machines.  This is the philosophy of the Java platform.  Java code is essentially operating-system-independent, and the Java software can be made to work on any computer, via the browsers on that computer.  Browsers, once you think about it, are a common feature of all computers, and so provide a way of interfacing with software in an operating-system-independent way.  Many other programming languages and systems are being developed to be more platform-independent.

I’m sure there’s a lot more information I ought to be giving you here, but this is a start.

Arch‘’“”

No comments:

Final Jeopardy

Final Jeopardy
"Think" by Merv Griffin

The Classical Music Archives

The Classical Music Archives
One of the oldest music file depositories on the Web

Strongbad!

Strongbad!
A weekly cartoon clip, for all superhero wannabes, and the gals who love them.

My Blog List

Followers