C++ Virtual Methods

In C++, the virtual keyword, when applied to class methods, aids in polymorphism. If a method is declared to be virtual, the most derived version of the method is executed when a call is made. If a method is non-virtual, the specific version that is called depends on how the method is called. If the method is called via a pointer to the base class, the base class method is called, if by the derived class, then the derived method is called. This definition is weak; an example is better, as usual:

Programming With Portability in Mind

Almost a year ago now I promised a series of articles on cross-platform C++. Since then, I have finished porting a relatively large C++ project that I wrote to Linux, Solaris, and Windows. I’ve learned that C++ is really quite portable and there are just a few guidelines that you should keep in mind.

C++ Question of the Day: std::map index operator

Jon asks:

Using Visual Studio Property Sheets to Manage Common Properties

Now that we have built Boost for Visual Studio, it sure would be handy to store the settings we need to use Boost in one place so that they can be easily set and reused. Visual Studio property sheets allow us to do just this. A property sheet is a collected set of settings which are stored in a .vsprops file. The file can be stored and reused between projects when common properties are desired. To create a property sheet for our Boost installation, we will first need to select the “Property Manager” tab of our project. [img_assist nid=415 title=Selecting the Property Manager Tab desc= link=popup align=none width=640 height=375] Next, right click on the project and choose “Add New Project Property Sheet…” [img_assist nid=416 title=Adding a New Property Sheet desc= link=popup align=none width=640 height=375] Now, choose the name and location of the property sheet that you would like to create. We are calling ours “boost.vsprops” [img_assist nid=417 title=Naming the Property Sheet desc= link=popup align=none width=640 height=375] Then, right click on the new property sheet and choose “Properties.” This will allow us to actually set the properties that the property sheet contains. [img_assist nid=418 title=Bringing Up the Property Sheet Properties desc= link=popup align=none width=640 height=375] The goal of this particular property sheet is make Boost easy to use. We will need to configure the includes directory and library directory of Boost to accomplish this. Select “Common Properties -> C/C++ -> General” in the property tree and set the “Additional Include Directories” to include your Boost installation’s header file directory. [img_assist nid=419 title=Setting the Boost Include Directory Property desc= link=popup align=none width=640 height=375] Finally, you will need to set “Common Properties -> Linker -> General -> Additional Library Directories” to include your Boost’s library installation folder. [img_assist nid=420 title=Setting the Boost Library Directory Property desc= link=popup align=none width=640 height=375] There, now we have created the Boost property sheet. Any time we want to use Boost from now on we just need to add this property sheet to our project and it will be ready to go. We can add many property sheets to our projects; so, we could create a library of property sheets for the various libraries that we regularly use.

Building Boost With Visual Studio

Unfortunately, if you want to download a pre-compiled Boost for Visual Studio, you are required to register for an account with boostpro.com. When I was looking to download Boost for Windows recently 1.38 was not yet available precompiled and I personally did not want to register for an account to download free software, so I built it myself. Fortunately, the process is very simple:

Now Tweeting

I’ve just installed the Drupal Twitter module which is supposed to add features such as automatic tweeting of blog postings. We’ll see how well it works or not. I’ll be tweeting under the name lefticus.

Paid Enhancements to Swig Starter Kit Coming Soon

I’m hoping to finalize the details of a paid contract to enhance the Swig Starter Kit soon. If the contract goes through, you can expect to see some significant enhancements. Specifically, Visual Studio, smart pointer and exceptions support will be added. Also, you can expect to see significant improvements in documentation. This particular client found me through the, “If you like this software, please consider hiring me,” license that I show on the google code project page. If anyone else is interested, I am available for C++ project work.

Real World Haskell: Chapter 5

Chapter 5 of Real World Haskell covers the creation of our first Haskell module. The chapter seems to come prematurely from my perspective. I am not yet concerned about making a module while I’m still trying to understand the language. One thing that did catch my attention is the Prelude.undefined special value which allows for easy creation of stub code: ` – This compiles but causes a runtime error if you try to execute it text :: String -> Doc text str = undefined` Bitwise Functions We also learn in Chapter 5 that the bitwise manipulations we have come to take for granted in C, C++ and similar languages is now a library module. This is the first point at which I can see an obvious point where C++ would make more succinct and readable code than Haskell.

GCC 4.4.0 Released

GCC 4.4.0 was released on April 21st. Notable changes include fascinating new optimizations for loops. Particularly, they include the ability for the compiler to automatically rewrite loops to take into account memory layout of the system. I recall distinctly in my Intro to Data Structures CS class the teacher using the example of a two dimensional loop which iterated the “wrong way” (causing many disparate memory look ups and cache-misses) as a classic performance killer. Example (from GCC’s website), GCC is now able to perform the following optimization:

Automated Algorithm Analysis Using GNU Octave

Jon and I were discussing the minnow scheduler and I suggested to him that it might be possible to use GNU Octave to run an automated analysis of his code and determine how well it will scale as the number of messages sent increases. The general notion is to use application run times to try and determine if the application has exponential, linear, polynomial, or logarithmic complexity. We can characterize the runtime of a function using regression analysis to generate a polynomial that represents our data and comparing the properties of the generated function to the known algorithm complexities we are concerned about. Specifically, we will be looking at the acceleration (2nd derivative) and jerk (3rd derivative) of our function. Positive acceleration means that the each unit of work performed takes longer to execute than the previous unit took. Positive jerk means that the acceleration is increasing, which is very bad. The characteristics are as follows: