Monthly Archives: September 2008

A cool multi-platform CDT use case

I previously blogged about the VitualBox SDK and the capability it provides to build some really interesting emulation environments, 3D graphics being the one I’m most interested in at the moment. And this is something I’m seeing in the embedded industry a lot lately. Hardware is expensive. These boxes we have on our desks are very powerful and relatively pretty cheap. Being able to emulate hardware during the software development phase of a project gives the developer the ability to get his code up and running much earlier.

So looking at how I’d build an emulator for a Linux set-top box that had 3d graphic capabilities, it quickly became apparent again how the multi-platform capabilities of the CDT gives me an top class C/C++ IDE to do work on all of the components. Here’s what they would include:

  • The 3D graphics emulator is a shared library that VirtualBox loads and, of course, runs on the host. I would start with doing it on Windows since that’s my main environment. I’d use either MinGW gcc or the Visual C++ compiler. CDT has support for building both but only debugging with gcc at the moment. But shared library debugging on Windows has always been trouble with the CDT so that might not be important. In the long run, I’d probably also want to do this for a Linux host environment.
  • The box would run Linux, of course. I’d need to be able to build the drivers that talk to the emulated 3d graphics thing. And I’d need to be able to build a bootable image with the kernel and the drivers and any core utilities I would need. Again CDT comes to the rescue, but I’d probably pick a commercialized version that automates Linux kernel development such as Wind River’s Linux platform builder. And I’d have to use my Ubuntu development environment on VirtualBox to run it since Linux is the only environment that really supports building the Linux kernel.
  • For the actual user space programs that provide the content, I can use the CDT again. This is the main environment that is used by the community building stuff for the box. gcc’s great cross compilation support makes it less obvious whether you’d do this on Windows or Linux. Linux would be a favorite since you can easily share your development workspace with the target using NFS. Something not as easy on Windows.

For me, this is the big advantage of the CDT. You have yourself doing host and target development on Windows and Linux, and even Mac if you wanted to, all using the same tools that have the same UI and keyboard shortcuts. Now, where’s that cloning machine so I can actually go build this thing…

Another legend has eyes on the future

I just finished reading an interview with another legend of the game programming industry, Epic’s Tim Sweeney (Mr. Unreal). First it was John Carmack from id (Mr. Doom) wondering how game developers will be able to harness multi-core technologies to improve game performance. Now I see Tim has a very interesting vision for how these technologies are going to change the industry.

It looks like both of them agree, multi-core general purpose processors will make graphics specific processing units obsolete, at least the fixed function parts of those graphics processors. But Tim seems to have a grasp of what that environment will look like. And it’s both exciting and liberating.

Essentially, he sees the return of software rendering, just like we had before the 3d hardware accelerator industry kicked in. Software rendering gives game programmers the freedom to implement whatever algorithms suite their needs, and they aren’t tied to the DirectX and OpenGL APIs which Tim says is really tying their hands. They can create whatever data structures they need to represent a scene and do whatever they want to slash that scene onto the pixels.

And he sees building that future with general programming languages and C++ in particular, instead of custom, hardware specific languages. Using C++, you have a shot at simplifying the programmers life, using the same technology for everything compute intensive. Game algorithms essentially come down to doing as many floating point operations at the same time as you can. Of course, this can be done in C++ with the right libraries, or even if necessary, a good compiler that can optimize your code to take advantage of whatever vectorizing capabilities your hardware has.

I anticipate this will be an exciting time for game engine developers. Certainly Tim seems pretty excited about it (and I highly recommend reading this article to catch some of that excitement.) And the good news is that we don’t need to invent new technologies to make it happen. C++ will do just fine (with a little help of the CDT, of course 😉

VirtualBox 2.0 gains an SDK

When you’re an Eclipse developer like I am who is taking advantage of Eclipse’s cross-platform capabilities, you need to have a bunch of platforms to test your work on. The incredible growth of virtualization on the desktop over recent years has been a huge help for us who don’t necessarily want their offices filled with a dozen machines.

I’ve tried them all and settled on VirtualBox, which was recently bought by Sun, as my Windows Laptop solution (I use KVM on my Linux desktop box). It has the best handling of screen resizing I’ve seen and thanks to the great support for this in recent Linux distros, the window for the VM flows nicely into my daily workflow.

VirtualBox released their 2.0 version last week. The big news is support for 64-bit hosts and guests (yeah, old news for other solutions, especially given VirtualBox still doesn’t support SMP 🙁 ). But what caught my eye was that extra download labeled ‘SDK’. Nothing get’s me more excited than an extensible platform (well, there are some things…). So I was quick to unwrap their new gift.

The SDK mainly covers APIs they’ve exposed to build VM management tools, similar to libvirt that’s used on Linux platforms. It lets you create, configure, and launch VMs. Cool, and maybe it’ll lead to better UIs for this, mind you the one they have is already pretty good.

The more interesting part of this was the last chapter of the SDKRef PDF file. It talks about the mechanism they use to allow communication between the guest operating system and the host. It allows you to create your own drivers that communicate through a virtual PCI device to a shared library on the host. Now the header files weren’t shipped as part of the SDK, but they are part of the open source parts of VirtualBox. At least the doc shows you how. Very cool.

Now this comes to one of the most pressing things I wished virtualization could do, use the 3D graphic chips on the host. If I want to experiment with some of the ideas I have for 3D Linux UI frameworks, and still use Windows for my day job, I need something like that. And with this capability opened up for us to use, I can quickly imagine how I could get OpenGL calls from a guest OS out through this mechanism to the host OpenGL libraries. And I guess I’m not alone. In the list of built-in users of this mechanism is a mysterious service called VBoxSharedOpenGL.

Time ripe for a Linux console?

I was watching my son the other day on our XBOX 360 that’s tucked nicely in our cabinet under the TV with our DVD player, digital cable box, and receiver. He was playing Halo 3, which looks great on our LCD HDTV, BTW. He’d break out once in a while and go back to the Dashboard and send a text message to a buddy then go back into the game and use the headset connected to his controller to talk about his school day with another buddy he was shooting at. It’s incredible how far consoles have come from the old Atari boxes we had when we were kids. Now they’re these multi-processing entertainment centers and communication devices that hook our kids up to the rest of the world.

It’s also interesting how he’s migrated away from our PC over to the XBOX. That could be because our PC is getting old and the 360 is actually a more powerful machine. But, still there are still things you can’t do on it. That would probably be solved if it had a web browser built into it. But for some reason, and correct me if I’m wrong on this, there doesn’t seem to be a web browser available for the 360. Weird. Too bad this is a closed platform that makes it really hard to get open source software, like the Webkit browser engine, ported to it.

So that got me thinking in the context of Linux. Why isn’t there a Linux console? Linux is slowly getting better for the desktop and it’s about to break out huge in the mobile space, wouldn’t it also work well in a box I can put under my TV and use with a wireless keyboard, or game controller with a headset, or with the controllers we have for Guitar Hero and Rock Band? I don’t see why not.

Googling the idea, you see the GP2X WIZ handheld I’ve blogged about in the past, and the sad story that was Indrema that rose with the hype of Linux in 2000 and crashed with the market realities of 2001. And yeah, Linux probably wasn’t ready in 2000. But nothing seems to be happening now.

And I’m sure there are economic roadblocks to making it happen. The companies in this industry are huge and are still selling the boxes for less than it costs to build them. Having an open platform makes it pretty difficult to collect the license fees that subsidize the hardware and platform development costs. You’d need a big player with big friends, similar to one of the Linux handheld alliances, to even think of making this happen.

But if it works for handhelds, why not on the TV. At least there it would have a bigger screen…

Get out your lambdas – C++0x

I saw a video of a talk by Bjorn Stroustrup, Mr. C++, who people I work with know I call “Barney”, affectionately, of course. In the video, he mentioned how badly he wanted to keep the name of the next major version of the C++ standard as C++0x and not have it slip into the next decade. Well, 2008 is almost over so it’s going to have to be C++09 if it’s to make it. But they are trying hard and making some progress.

And hopefully it does. C++ is due for a good shot in the arm, something to get people excited about. Working every day in Java as I do, and yearning for my C++ days, there are a few features in Java that would be exciting to have in C++. Not many, but there are a few :).

And one of them appears to be ready to be included in the standard, lambda expressions. Now Java doesn’t have pure lambda expressions, but the inner class support comes close. And with C++0x support for more general lambda expressions, I think we have a winner on our hands. Here’s an example:


int x;
calculateWithCallback([&x](int y) { x = y; });

This ain’t your father’s C++. To explain what’s happening, we’re passing an anonymous function that takes a parameter y, and we pass along with it a closure which passes on some of the context with the function, in this case a reference to x. Later on the calculateWithCallback function does something and then calls our function with a parameter value for y. We then execute and assign the value to our x and return.

Anyway, very cool. Callbacks is a very popular design pattern and we use it all the time when programming Eclipse plug-ins. Being able to do something like this in a concise manner in C++ will be very useful and help bring C++ into a new decade, or whenever they get the standard ratified.

exit() is your friend

I was just reading the Google Chrome cartoon book (an interesting way of presenting designs). One of the things they talked about was how having browser tabs in separate process helps with memory consumption because memory gets cleaned up with the process exits. Otherwise, the constant malloc/free cycle ends up with memory fragmentation that is hard to get rid of.

That brought back some memories. In my early work on a code generator, I used the same philosophy. I created a pretty big object model in memory after I parsed the input, but I never implemented any of the destructors and never called delete. Didn’t need to. It was a short lived process and the call to exit() at the end freed up all the memory anyway. And it’s pretty fast! Lot faster than calling delete for each object I created.

Anyway that worked great. Until another team decided they liked my object model and wanted to use it in the main tool. Unfortunately that tool was a long running process and they had to add in the memory management to survive. So much for exit() is your friend. Worked for me, though.

Of course all the garbage collector languages deal with this for you. Makes me wonder why GC in C++ hasn’t become more popular. There are C++ garbage collectors like the one from Hans Boehm. But I guess if you’re moving to that paradigm, you might as well use Java.

Coming Live from Google Chrome

Well, it’s live and I’ve downloaded it and am using it to write this blog entry. It’s Google Chrome. It’s a beta, but from what I’ve seen in the couple of minutes I’ve used it, it’s delivering as promised. Very fast and smooth, even typing here. Better than Firefox? Seems like it, but maybe it’s the chrome blinding me. And given the news volume about it, there’s a lot of people speculating about what Google is trying to accomplish with this thing.

At any rate, if it is about making the Web the OS as we’ve been trying to do for centuries now, what does it mean to C++ application developers? How do they make their applications relevant in this new world? Is it all over? Do we throw away our C++ compilers and pick up a book on PHP?

I strongly believe there will always be a role for a close to the silicon programming language like C++. Whether it’s for resource constrained devices like mobile platforms, or whether it’s for high performance apps like image processing or simulations, there’s still that need.

What may change is how these C++ apps communicate with the user. I can easily imagine a Web-based UI for C++ apps, similar to other Web 2.0 platforms. Who says the server side needs to be Java or PHP? It could easily be a C++ app. What we need, though, is a clean way to program such a UI. C++ widget programming has always been a challenge, but wait until you change the paradigm like this.

This is one reason I’m keeping an eye on the “Webification of SWT” part of the Eclipse e4 project. The lessons learned and the technology choices made there should be portable to a similar effort in C++. Maybe there’s already a C++ widget set out there that we could use to start, like wxWidgets, maybe something else, maybe something new. Either way, it’s time for C++ developers to start thinking about what this all means to them.

Google has their own browser!???

Apparently the word leaked on an unofficial Google blog site and they followed up with an “oops” official blog post. Either way, the word is out and the web browser “industry” is in for a shake up. Google is releasing their own web browser called Google Chrome. Apparently it includes pieces from Webkit (I’m guessing the browser part) and Firefox (I’m guessing the chrome part) and will be developed as an open source project.

The first beta will be released tomorrow (Tuesday). I’ve heard rumors but always dismissed them. Why would they do that when we have a handful of pretty good browsers already. I guess the rumors were true and given the beta comes out now, it’s been in the works for a while.

But still, you’ve got to ask why. Why couldn’t they just contribute the stuff the felt was important to Firefox or Webkit. I’m going to guess that it’s because sometimes getting your ideas into an open source project is hard. Everyone with a few open source miles under their belt knows how hard it is to influence a community at times and this isn’t exactly the first fork in the industry. And when you have the resources and experience Google has, I guess it made more sense for them to fork.

My favorite quote is from the cnet news article where I first stumbled on the news: “Open sourcing the code is a smart way to avoid the ‘Google wants to take over the world’ fear, but it seems that Google has ambitions to create a comprehensive Internet operating system, including a browser, applications, middleware and cloud infrastructure.”

Very intriguing. And this is one of the reasons I’m very interested in Android. Because that’s what it is, an internet operating system for mobile. It isn’t much of a stretch to take it beyond the cell phone so it’ll be very interesting to watch where this goes. (And, yeah, I think Microsoft should be paying attention to this.)