Friday, February 29, 2008

inline functions, the good, bad and ugly

I learnt while reading from C++ FAQ Lite at http://www.parashift.com/c++-faq-lite/ about the good, bad and ugly aspects of inline functions. So here they are

Inline function can make you code faster if used, but then if its used a lot of places as inline function, the code bloats up. This can also lead to more page faults and hence leading to serious performance issues. Sometimes function optimizations can actually lead to a smaller code being generated because code for function calls(basically stack usage) is optimised.

Did I say page faults can increase, but then if there were two function on different pages, then thrashing could have been more without inline functions. Also its more likely that code would be at the boundary of cache, so cache memory thrashing is induced there.  But then again if the code is at right in the middle of the cache then fetching code of another function in another page would take toll on memory via thrashing.

So is inline good or bad. Now that something very subjective I would say. Just like not every garment looks beautiful to the customer, inlineing is also based on the usage. A simple direct answer may very well be wrong.

Tuesday, February 26, 2008

inline function, a move over #define

One the feature of C++ that I find very cool is inline function. It actually kills all those crazy interview questions which are asked just to confuse you over brackets. I dont remember ever using the complicated #define in C to anything more than example programs. Crazy part of inline funtion is that though u code almost as a normal function call but it gives the advantages of writing code right where u called the function. No more making sure that you have brackets in place and how its going to expand at all the places, how its going to take in the parameters passed to it, how will the return value be determined. Dump all that. How to stuff is here

void foo()
{
  int a,b, c;
  c = bar(a,b);
}

inline int bar(int a, int b)
{
  //Just do something here
   return something;
}

So you have the function foo calling function bar, but as bar is inline code for it would be placed right where it was called in foo. So we see how inline function has simplified life in C++. Any question of yours in this regard would be appreciated and I would try my best to answer it.

Monday, February 25, 2008

Multiparadigm Programming

I had never ever known if any term like that ever existed in this world. But recently I did. Now what it actually means is that instead one we use several programming paradigms to the best of effect while coding.

As Leda designer Tim Budd holds it: The idea of a multiparadigm language is to provide a framework in which programmers can work in a variety of styles, freely intermixing constructs from different paradigms. := (wikipedia)

From what I understood is that C++ provides us means to make use of objects and design patterns as well as give us the ability to make use of Templates. That is to say that we make use of OOPS as well as generic programming paradigms makes C++ really powerful.

Saturday, February 23, 2008

Why is this blog here

I am software guy. I love programming in C/C++. I feel these two are the coolest of all available in the world. C is actually a sea and C++ is obviously one step ahead. No one can completely learn it. Of late I have not been into either and have not been learning more about it. So I hope with this blog I will be learning as well as keeping the knowledge somewhere easily accessible to me as well as other. I hope this blog makes good reading for all. My general blog is at http://the100rabh.blogspot.com