Discover the power of algorithms

Complexities of algorithm, thier applicability. Optimization techniques associated with diffrent algos.

Discover Power of Blogging

What is Blogging , is it a Dream or Passion or Award or Making Money ?

Think Diffrent, be creative

Let's see how much conclusion one can draw from it. This will help testing your creativity.

Discover the power of technology

Technolgy, Programming, Optimization , Gadgets and more...

Discover the power of Blogging

Google widgets and gadgets.

Mar 18, 2010

Perception a boon or a killer ?

Perception is considered to be starting point of thinking. In most of the cases perception starts with our experiences we have from life.

If we look thinking steps it would be:-
a) We see, observe or feel.
b) We percepts i.e. start thinking and analyzing.
c) We conclude and take actions.


Most of us just ignore the step (b), which i want to highlight with examples and will see some steps to improve this.

Lets take an example of one short story showing perception role in real life:-
In Australia, the one dollar coin is much bigger than two dollar coin. One day, one big guy and his friend offered five-year old Johnny a choice between two coins: a one dollar coin and the small two dollar coin. He could take and keep whichever one he wanted.He picked the bigger, one dollar coin.His friends laughed and giggled.Whenever they wanted to tease Johnny they offered him again this choice of coins.He always took the bigger one.He never seemed to learn.
   One day an adult saw this and called Johnny over.He told Johnny that although the smaller coin was smaller it was actually worth more."I know that", said Johnny. The adult man just got stunned from his answer. Johnny added "If i had taken smaller one first time, then how often they will offer me again".

With the above example it's very clear that perception made by big guys for that small kid was absolutely wrong. And utilizing same perception kid actually got the benefit.This example reveals us that don't precept that you are the most intelligent and the "only one".Always keep in mind that you cant fool people all the time. So be very cautious in case you start perceiving things.

Lets take one more practical example.








This is a small story indicating how perception can change with time and circumstances.

Rishita joined college after stepping out of school world. She made few friends and Pinky was one of them. They soon became good friends and shared a small world together of friendship and trust with lots of fun and enjoyment. One day Rishita was not feeling well so she asked Pinky to submit her assignment on her behalf, as the assignment marks were to be added to final score.

She was relieved that her assignment will be submitted on time. But next day she came to know that her assignment was not submitted and even Pinky was absent.
Rishita felt cheated and was very annoyed over Pinky. More important was that Pinky didn't even contact her once. One week passed by and Pinky joined back but Rishita decided not to talk to her. She created a perception for her and acted accordingly. Pinky tried to contact her many times but all in vein.

Few months passed by. Rishita was talking to one of her classmate and when Pinky was mentioned, she suddenly came up with an abrupt remark on Pinky's credibility. Then her classmate asked the reason for such comment and Rishita told her everything. Then her classmate broke her perception by telling truth about Pinky's unavailability.The second side of story gave Rishita shock of her life.

The day Pinky was going to submit Rishika's submission, her younger brother had a bad road accident and she was occupied for nearly 2 weeks with her brother's recovery. This was the reason she couldn't even inform Rishita. when she joined back she tried to contact Rishita, but Rishita's perception deprived her of the best friend she had.

At this time she realized that her wrong perception due to a single incident and incomplete information cost her best friend she had.

This example reveals that perception if made wrong can be a killer.

 A perception taken at a time plays very important role in real life situation.
As we saw perception taken by big guys was totally different from kids perception.
To kid perception made by big guys was a boon to him. We also seen
perception can make or break friendship.

Lets take one more example to understand that perception is a boon or a killer?



An old man of ninety goes down to Hell. As he wonders around he sees a friend of his, about the same age, with the most beautiful young woman on his knee.
He ask, "Is this hell? You seem to be having a good time."
The friend replies, "it is indeed hell, i am the punishment for the young lady."

This humorous example shows that perception can vary from people to people and its very difficult to get the right one. If you apply logic then also its difficult to create right perception. Perception as we seen can be a boon or it can be killer at times. So, just be careful whenever you precept things, try to add more and more dimensions to your thinking process before taking an action.

Hope you enjoyed reading the post.

Keep Rocking,
-Tajendra



KISS optimization principle.

Process/Code optimization is all time burning issue for projects/products in Industry. If we search for optimization techniques we get lots of complex theory and lengthy algorithm which claims to give optimizations. But its not advisable to run after such solution at very first level. One need to understand the need for it and that's what KISS principle is all about.


The "keep it simple, stupid" (KISS) principle, calls for giving simplicity a high priority in development.
So one need to consider this at the time of development  the reason i think is "One can easily apply  optimization on simpler code instead of complex one."

It is very similar to a maxim from Albert Einstein's that states, "everything should be made as simple as possible, but no simpler.", the difficulty for many adopters have is to determine what level of simplicity should be maintained. In any case, analysis of basic and simpler system is always easier, removing complexity will also open the door for code reutilization and a more generic approach to tasks and problems.

 So, whenever you start development keep this "KISS"  principle in mind.

Some optimization Link from Amazon:-
Combinatorial Optimization (3 volume, A,B, & C)
Elements of Dynamic Optimization
Linear Programming with MATLAB (MPS-SIAM Series on Optimization)



Mar 10, 2010

C++ Brain Food : A must solve c++ question.

I really like this c++ question. It really helps us to understand exception handling mechanism of c++.

Lets check you will get it right or not:-

Don't just execute code with compiler to get the result, try out by doing dry run.

What output does this program generate as shown? Why?

#include

using namespace std;

class A {
public:
A() {
cout << "A::A()" << endl;
}
~A() {
cout << "A::~A()" << endl; throw "A::exception";
}
};

class B {
public:
B() {
cout << "B::B()" << endl; throw "B::exception";
}
~B() {
cout << "B::~B()";
}
};

int main(int, char**) {
try {
cout << "Entering try...catch block" << endl;

A objectA;
B objectB;

cout << "Exiting try...catch block" << endl;
} catch (const char* ex) {
cout << ex << endl;
}

return 0;
}






Mar 5, 2010

What is Inline function in c/c++? A discussion on its Advantages,Disadvantages,Performance and Uses Guidelines.

Inline function is the optimization technique used by the compilers. One can simply prepend inline keyword to function prototype to make a function inline. Inline function instruct compiler to insert complete body of the function wherever that function got used in code.

Advantages :-
1) It does not require function calling overhead.
2) It also save overhead of variables push/pop on the stack, while function calling.
3) It also save overhead of return call from a function.
4) It increases locality of reference by utilizing instruction cache.
5) After in-lining compiler can also apply intra-procedural optimization if specified. This is the most important one, in this way compiler can now focus on dead code elimination, can give more stress on branch prediction, induction variable elimination etc..



Disadvantages :-
1) May increase function size so that it may not fit on the cache, causing lots of cahce miss.
2) After in-lining function if variables number which are going to use register increases than they may create overhead on register variable resource utilization.
3) It may cause compilation overhead as if some body changes code inside inline function than all calling location will also be compiled.
4) If used in header file, it will make your header file size large and may also make it unreadable.
5) If somebody used too many inline function resultant in a larger code size than it may cause thrashing in memory. More and more number of page fault bringing down your program performance.
6) Its not useful for embedded system where large binary size is not preferred at all due to memory size constraints.








Performance : -
Now covering the topic which most the people are interested in the "Performance".
In most of the cases Inline function boost performance if used cautiously as it saves lots of overhead as discussed in our Advantages section above but as we have also discussed  its disadvantages one need to be very cautious while using them. Today's modern compiler inline functions automatically, so no need to specify explicitly in most of the cases. Although placing inline keyword only gives compiler a hint that this function can be optimized by doing in-lining, its ultimately compiler decision to make it inline. Though there are ways to instruct compiler too, for making a function call inline like one can use __forceinline to instruct compiler to inline a function while working with microsoft visual c++. I suggest not to use this keyword until you are very sure about performance gain. Making a function inline may or may not give you performance boost, it all depends on your code flows too. Don't expect a magical performance boost by prep-ending inline keyword before a function to your code as most of the compiler nowadays does that automatically.

As we have seen inline function serves in terms of performance but one has to use it with extreme cautions.

I have prepared a few guidelines for its use.
Uses Guidelines :-
1) Always use inline function when your are sure it will give performance.
   Recently i got very good example showing immature use of inline function.
Suppose you have used inline function and for some reason compiler rejects it.
Well, when the compiler cannot inline a function, it generates a static definition of the function instead. In other words, the code for the function is generated just like the code for a static function. This means that every translation unit in which an inline function cannot be inlined will get its own copy of the function, which can increase the size of your program. Most compilers will report warnings when a function cannot be inlined. You should pay attention to these warnings to determine if some functions should not be inlined in the first place.

There is one more detail with inline functions that you should be aware of. Suppose you have chosen to use a local static variable in an inline function:

inline void foo()
{
static int index;
// ...
}

Next, suppose for some reason, the compiler cannot inline this function in several translation units. Each translation unit will then have its own static definition of foo(). But, this means that each version of foo() may also have its own copy of the static variable index! Clearly not what you want. So avoid putting static variables inside of non-member inline functions.
2) Always prefer inline function over macros.
3) Don't inline function with larger code size, one should always inline small code size function to get performance.
4) If you want to inline a function in class, then prefer to use inline keyword outside the class with the function definition.
5) In c++, by default member function declared and defined within class get linlined. So no use to specify for such cases.
6) Your function will not be inlined in case there is differences between exception handling model. Like if caller function follows c++ structure handling and your inline function follows structured exception handling.
7) For recursive function most of the compiler would not do in-lining but microsoft visual c++ compiler provides a special pragma for it i.e. pragma inline_recursion(on) and once can also control its limit with pragma  inline_depth.
8) If the function is virtual and its called virtually then it would not be inlined. So take care for such cases, same hold true for the use of function pointers.


That's it from my side, I hope you enjoyed reading the post.



Mar 4, 2010

The unbalanced discovery boosts the unseen blast.

Lets see how much conclusion one can draw from this post topic.
This will help testing your creativity.Such random exercise help one's to open their mind, to let it fly in this big sky of imagination. Let's see how far you can fly :)



Mar 2, 2010

How to achieve code portability ? Basic 10 quick tips.

Code portability basically refers to making source code able to compile on different platform without making any changes in source code.
While coding its very important to keep portability in mind.The best way to introduce code portability is while coding.Keeping certain things into account we can achieve code portability with lesser effort, which we will discuss in this post.There are certain tools too which detect portability problems on source code, its a post processing of code and requires extra effort.
Non-portable code introduces problems like maintenance of different versions, reduces readability, reduces understanding of code etc...
Efforts needs to make legacy or old source code portable, can really make you feel lost in this big programming ocean. So, the best policy is to keep portability into account while writing code, it saves lots of time and efforts on rework. Big question now is - "How to write portable code?".Our source code should be compatible with different environment like different processor, different OS, different version of libraries etc... In this post we would focus on basic tips need to be kept in mind while writing code. 

1) Don't assume data type size to be constant across platform, as it may change with platform.
             Many a times programmers makes a common mistake by assuming size of pointer and long same.If in some expression sizeof(long) is used, it may give different result on 32-bit and 64-bit OS version. Like if we talk about Microsoft Visual Studio running on 64-bit OS version the pointer size would be 8 byte and size of long comes out to be 4 byte. Program written with such assumption would give false result or may even get crash.So, one has to be very cautious while using data type size across the platform.

2) Don't use specific system constants.
            System specific constant should not be used as they are not portable, we are some time not aware of them also. 

3) System file/folder path notation may vary on different platform.
           When working with file path one need to be cautious for example "\\testfolder\\TestFile.txt" will work on Windows but give error on Linux.For this one i recommend to use forward slash "/tesfolder/TestFile.txt" , it would work well on both windows and Linux.

4) Avoid using system specific models/libraries.
         Don't use system specific models/libraries like Event handling model, Threading libraries, File Creation libraries etc.. . As they are not compatible across platform. Write a wrapper around such models and within wrapper use generic portable libraries. For example, Windows even handling model is totally different from Linux. Windows have special mode for handling events, like we may not find timed wait for multiple object on other platform.

5) Always write default statement in switch case.
         Many latest compiler gives compilation error if default is not specified.

6) Always specify return type for functions. 
         Many latest compiler gives compilation error if return type is not specified.

7) Always specify type with static variables.
         Variables declared with static keyword must contain data type with it, some old compiler take int as default type but modern compiler will generate compilation error for it.

8) Always take care of scope of variable.
        Like some compiler support variable scope limited to for() while some compiler dont.
    For example:-
        Don't prefer writing code as below (Non-portable code).
        {
           for(int i ; ;)
          {
          //do some thing
           }


           for(int i ; ;)
         {
          //do some thing
          }

        }


         Prefer writing code as below (Portable code)
        {
           for(int i ; ;)
          {
          //do some thing
           }

           for(int j ; ;)
         {
          //do some thing
          }

        }

9) Don't use C++ commenting style in C code.
      Don't use // commenting style in c code, as compile other then microsoft visual studio may generate error for it. Prefer using /* */ commenting style.

10) Take care of include depth for header files and also for file code size.
       Microsoft visual studio compiler generated error like "internal compiler error"  if include depth is too large or file size exceeds certain limit. Always take care of file size and include depth. 

I have tried to cover 10 basic tips for code portability for beginners though there are several other areas too, where we need to focus on advanced portability issues, for e.g. dealing with classes, virtual functions, exception handling, compiler directives, run-time identification. I will cover this topic separately bye for now.
  
Hope you enjoyed this post !

Keep Rocking
-Tajendra



What's the difference amongst code portability, software portability and application poratoability ?

Many people gets confused of terms Code Portability, Software portability and Application portability.
Lets understand the differences amongst them. Application portability means that application is designed in a way that it can run independently without actually installing its file on the system. A portable application did not install any file on the system and can be run with the help of removable devices like USB, portable hard drive, CD, flash drive or floppy disk. Application portability is often get confused with Software portability, where as Software portability refers to designing of software in a way that its source code can be compiled on different platform without any changes. Software portability is also referred as code portability, both the terms can be used alternatively. Application portability does not implies that it can run on multi-platform, it only implies that it runs independently on system from its storage location only. Portable application saves or read its configuration from its storage location, it does not leave any files on the system its running upon. This feature make the application portable.
So now difference is very clear between software portability and application portability.

Hope you enjoyed the post !
-Tajendra



Mar 1, 2010

"Lathmar Holi" a traditional Indian Holi showing Radha's Sweet Festive Revenge

Today is Holi, the Indian festival of colors. One will not find as many color as found in this festival. Auspicious red, Soothing silver, Sunkissed gold, Pretty purple, Blissfull blue, Forever green all colors are there. People used to play holi by forgetting all thier previous rivalry and used to enjoy great indian cusine of sweets, typical indian "bhang",traditional drink called as "thandaii", play color names as "gulal". Its all very colorful and you can put color to anybody by just
saying "Bura na mano holi hai".
Holi get celebrated in many ways and today i have chosen to write on "lathmar holi" which is treated as epicenter of holi in India. I have chosen Lathmar holi because it is unique in the sense that here women chase men away with sticks. Males also sing provocative songs in a bid to invite the attention of women. Women then go on the offensive and use long staves called "lathis" to beat men folk who protect themselves with shields. Before moving ahead with it lets undestand the reason of Holi celebration there are several sagas behind it "Love of Lord Krishna-Radha", "Legend of Prahlad and Pootna" and "Legend of King Hiranyakashyapu". I like "Legend of Krishna and Radha" the most as it spread message of love.
Krishna being a very mischievous kid plays lots of pranks with Radha and her friends (Gopies). Yashuda son Krishna once asked her that "why Radha so fair and i am so dark", replying to him Mother said "If you are too much jealous of her than put dark color on Radha so there will be no color difference". Krishna did same by putting dark color on Radha. Since then people celebrates Holi by playing colors with his/her loved ones.
One can ask question then from where this Lathmar Holi came from, so answer is its from Radha's and Gopies.
Its a battle of love between Nandgaon's men (Lord Krishna's Place) and Barsana's women (Shri Radha's Place).
Lord Krishna was famous for palying pranks with Gopies of Vraj and Gopies too enjoy this by showing thier love anger over it. So, continuing this ritual Men and Women of Vraj even today clash in a colorful display of battle of the sexes. Men of Nandagow tries to invade Barsana with hopes of raising their flag over Shri Radhikaji's temple (Most famous temple dedicated only to Shri Radhika in India). In response Barsana women with thier full preparation attacks men with long wooden stick termed as "lathis" to take sweet festive revenge for pranks played by Lord Krishna.Slowly it turns up into a love battle where men attempt to reach Shri Radhikaji's temple defending themselves with shield.Funny part of this battle is if men gets up into hold of women then they are forced to dance in female attire too. This Love battle showing Radha's sweet festive revenge is Known as “Lathmar Holi”!! also famous as BRIJ KI HOLI.
One can rightly say here that "It happens only in India". Lets keep this divine love of Krishna and Radha alive deep in our hearts, so that we can spread message of love and happiness in this world of hatred

Happy Holi,



Feb 28, 2010

How to add label cloud to your Blog ?

Its very easy to add label cloud to your blog.
Just follow below step to make your blog tag cloud enabled.

1) Go to Layout section of your blog.
2) Add gadget named as "label"




3) Configure labels as shown in above figure to Display type "cloud".

This would help your blog look more organized and easy for navigation too.

Keep Blogging
-Tajendra



Feb 27, 2010

Understanding which is faster Post or Pre increment operator ( i++ vs ++i ) ?

In c++ pre and post operator are used with variables where one need to just increment or decrement value by 1.For incrementing value ++ operator can be used and for decrementing -- operator can be used.
Its use is very simple one can easily say ++i or i++, to increment its value by 1. Many a times i found people very confused about it's usage (at beginners level) and some professional showing lots of concerns about its performance .That's what made me writing this post.
lets focus on its use first:-
One can now ask question that why there are two different version present for if we simply need to increment or decrement the value.
Lets take one example to see its effect in expression for post and pre increment operator :-

a) x = ++y; //pre increment
b) x = y++;//post increment

For above two expression value of x will be different. In expression (a) value of y would be incremented first then it would be assigned to x. And in expression (b), x would be assigned value of y first and then y would be increment. So if the value y is 5, then value of x would be 6 in expression (a) and its value would be 5 in expression (b).




We are now aware of its usage and impact in an expression, now lets find out which is better ?
To a much extent we can say that pre-increment is faster then post-increment operator. If we talk about independent statement containing just pre-increment and post-increment operator then pre-increment is faster (without compiler optmization).but, if we talk about integer variable the difference is almost negligible.It would be one or two cycle in unoptimized c++ code.As with pre-increment operator we did not need temporary location to store value, value is directly incremented and assigned where as in post-increment operator we need to store value in temporary variable. So with data type like integer, pointers no major performance can be achieved but if we talk about classes one should prefer use pre-increment operator.
Lets try to implement both operator it would help us gain understanding about it :-
pre-increment operator
++i
int PreIncrement(int i)
{
  i = i+1;//incrementing i
return i;
}

post-increment operator

i++
int PostIncrement(int i)
{
  int tempvar = i;//temporary storage
  i = i + 1;//incrementing i
  return tempvar; //return tempvar
}


With above example its very clear that pre-increment is better and efficient then post-increment operator.
Again i want to make one point clear that it would not improve performance for data type like integers, pointer with advanced compiler you will not see any difference in assembly code too.I have written one test code to show this, lets look at it :-



int x =0;
001F361C  mov         dword ptr [x],0 
int y =1;
001F3623  mov         dword ptr [y],1 
x = ++y;
001F362A  mov         eax,dword ptr [y] 
001F362D  add         eax,1 
001F3630  mov         dword ptr [y],eax 
001F3633  mov         ecx,dword ptr [y] 
001F3636  mov         dword ptr [x],ecx 
x = y++;
001F3639  mov         eax,dword ptr [y] 
001F363C  mov         dword ptr [x],eax 
001F363F  mov         ecx,dword ptr [y] 
001F3642  add         ecx,1 
001F3645  mov         dword ptr [y],ecx 
y++;
001F3648  mov         eax,dword ptr [y] 
001F364B  add         eax,1 
001F364E  mov         dword ptr [y],eax 
++y;
001F3651  mov         eax,dword ptr [y] 
001F3654  add         eax,1 
001F3657  mov         dword ptr [y],eax 


With above disassembly code its clear that is no much impact on assembly instruction, code generated is almost same for both the cases.With all the analysis done so far, i am still thinking about post-increment operator.All points are going in-favor of pre-increment operator but there should be some benefit of post-increment operator too, where it can be used. Finally i found one such condition where post increment is better then pre-increment operator, lets look at following example :-
a) x = arrIntValues[i++]
b) x = arrIntValues[++i]

In above case expression (a) is better than (b) because in the second case,the address calculation  of the array element has to wait for the new value of i which will delay the availability of x for one or two clock cycles.But it should be used cautiously since if you are making such changes in programs it may change code behavior.

Time to conclude now. As we have seen usage and comparison of pre/post increment operator, which shows that both are equally good if used for primitive data types with optimized compiler option.For non primitive data type one should use pre-increment operator. And finally it depends upon your code condition too, as we have seen one condition where post-increment is more efficient then pre-increment operator.Whole discussion    is also applicable for pre/post decrement operator too.

Hope you enjoyed the post, Cheers,
-Tajendra




Feb 24, 2010

Sachin's record 200* In ODI vs South Africa, memorable milestone in cricketing world


I can’t stop myself writing on Sachin's 200, it’s a mmmmm what can I say just got spellbound from his performance.Its a magical mesmerizing memorable milestone performance from maestro the “Sachin Ramesh Tendulkar”.

Sachin slammed 200 not out today against one of the strongest ODI team South Africa at Captain Roop Singh Stadium Gwalior.




It’s a working day in our company and all are just busy with their scheduled work. And suddenly one guy screamed from his cube that “Sachin made 185 not out” this news just spreads like wildfire (technically like viruses on network). It infected almost every guy and all moved to our chill out zone which have television set. Quickly whole room got filled, each and every corner of room got occupied. All intellectuals who fights like anything in meeting rooms with their logical reasons were in total sync with each other and why not as all were  talking about the “Sachin Tendulkar”. All guys present in room had several positive comments on Sachin,
all were busy in proving that "They are the biggest fan of Sachin" and everyone in thier heart wanted Sachin to cmake first ever double century in ODI. 
Sachin crossed the magic number of 194 runs in 46th over and all went up clapping with a big smile on everyone's face.With this Sachin created a record of making a highest score in an ODI by breaking Saeed Anwar's record of 194 runs. But everyone was still holding breath eying for much bigger celebration.
Its now 47th over, Sachin reached 199 mark still requiring one golden run.We all were waiting for it and in next over we were hoping to see Sachin on strike but Dhoni faced all the 6 balls brilliantly and Sachin still on 199 mark :(. Despite Dhoni doing his job well, he was not getting any attention as everyone wanted to see Sachin on strike. And finally Sachin got strike in last over, Langeveldt the bowler, bowling 3rd ball of the last over, all stage set for Sachin to reach the milestone of double century. There was a complete silence in the room for a while, all praying for Sachin's 200. All were tensed but Sachin looking very confident and finally Langeveldt delivered the ball and Sachin guided ball for single run. All went up on their feet and this time celebration was much bigger and louder. Everyone were so happy and were feeling very proud. This moment will remain for a long time in memory of all the cricket lovers. 

This event was so big that when i entered "Sachin's 200" search string on google search, it fetched almost 2400 pages within minutes of his double century.
Sachin got more then 70 records under his name, for detail check this link :- 

Sachin is a living legend of cricketing world and adding to his greatness he dedicated this marvelous innings to Indian people.Sachin tussi great ho, jahanpanah tofah kabul karo :)




How to allocate memory dynamically on stack ?


I read some time back that memory operation on stack is much faster than heap. With this
information the first thing came into my mind was that if we get a way to allocate memory
dynamically on stack it would surely help us to optimize memory operation cost. I started
searching for it and finally I found one such way J.
Before going into its detail let’s take a look at dynamic memory allocation on heap.

Generally when it comes to dynamic memory allocation new/malloc  the well known calls
Comes into mind. They help us to dynamically allocate memory on the heap.

For e.g.
  int FunctionA()
{
   char* pszLineBuffer = (char*) malloc(1024*sizeof(char));
    …..
  // Program logic
     ….
  free(pszLineBuffer);
  return 1;
}

Above code would allocate 1024 bytes on heap dynamically. After the complete use of variable szLineBuffer, we
need to free memory also (free/delete can be used for it).  So, one has to  keep track of deallocation call,
else memory leak will get introduced.

Now coming back to our question, is there any way by which we can allocate memory dynamically on stack.
So the answer is yes. We can allocate variable length space dynamically on stack memory by using function
_alloca. This function allocates memory from the program stack. It simply takes number of bytes to be allocated and
return void* to the allocated space just as malloc call. This allocated memory will be freed automatically on function exit.
So it need not to be freed explicitly. One has to keep in mind about allocation size here, as stack overflow exception may
occur. Stack overflow exception handling can be used  for such calls. In case of stack overflow exception one can use
_resetstkoflw() to restore it back.

So our new code with _alloca  would be :-

  int NewFunctionA()
{
   char* pszLineBuffer = (char*) _alloca(1024*sizeof(char));
    …..
  // Program logic
     ….
  //no need to free szLineBuffer
  return 1;
}

Now let’s check out what will be the advantage of _alloca over new/malloc :-
1)      We have saved overhead of new/malloc.
As _alloca() got very little overhead of allocating memory on stack.
2)      No need to free memory explicitly. So, deallocation cost will be zero.
3)      If function like FunctionA() got multiple time in your program it may cause heap memory fragmentation on a long run,
Which would be saved with NewFunctionA() as stack memory never goes fragmented.


Now let’s check out what will be the disadvantage of _alloca over new/malloc :-
1)      One has to be cautious while using alloca for huge blocks.
2)      Its scope is limited to a function call.
3)      As stack overflow is not a standard C++ exception, one hast to use structured exception handling for it.


I hope you enjoyed this post.
-Tajendra



Feb 22, 2010

How to register Blog with google search ?

If you are a new blogger and want to get noticed on internet, then you can use google search engine for it.
Google search engine is the straight and most convincing way of attracting web traffic. Start writing good content , just be patient and surely your blog ranking will increase.

Follow below step to register it with google blog search :-

1) Got to link Goggle Blog Search. (http://blogsearch.google.com/ping)
2) Followin page would appear under it.


3) Enter your blog address into it.
4) Simply submit it.

Remember your page would not become famous overnight. It takes time and most importantly its your content which is your blog success mantra.

-Keep Blogging



Feb 21, 2010

Google Buzz started with Buzzing Issue (Breaking User Privacy Law). Is it a genuine issue or smart trick?



Google Buzz ?
The most buzzing event of Google nowadays and it’s also buzzing loud on all technical news too. Let’s find out what is so buzzing with it.

Google buzz is actually a smart way of short and sharper communication. The most attractive thing here is that it’s got integrated in your Gmail inbox, so don’t need to go onto some other link to access it.

Google Buzz is initiative toward getting strong in social networking domain. Currently Facebook covers almost 46% of the social network traffic, myspace 19% and you tube 14%. Google buzz can be said an answer to Facebook.

Google buzz comes with navigation in your gmail inbox. Buzz uses the people you email and chat with most often to build the first iteration of your network. This network was originally created by default and that is the biggest threat to privacy.Since Google buzz auto-follow people you communicate with on Gmail or Google Talk. Google buzz started with this issue and attracted lots of focus from the privacy organization. Many privacy organizations registered a strong concern over it. And Google buzz becomes the hot discussion topic of everyone. Every product tries to get focus with its new feature but Google buzz got the focus with its user privacy issue. Whatever Google buzz as a product ultimately attracted huge users and organization.
Finally Google apologizes for this and they have planned to launch it with more transparency and control features.It is still a mystery whether it’s all intended or a genuine user issue.

But overall Google buzz is a great feature to use; it helps one to share quickly text, videos and links with your network.
I have already starting buzzing with it and let’s see how far this feature will go.

Keep Blogging and Buzzing



Feb 20, 2010

How to register URL with search engines ?



Everyone wants to get noticed on Internet after launching very first content on new site :).
There are several ways by which one can get noticed on internet like search engines, backlinks, social networking sites, forums etc...I have explored search engine registration mechanism.
Its not very difficult to register your blog/website with famous search engine. Search engine are the most effective tool to get web traffic to your blogs/website. When it comes to search engine google, yahoo and msn live search are the most used option nowadays.





I have collected following links which can be used for submitting your URL :-
Above search engine shares 90% of all the hits. So registering to above link would be enough to get noticed at very first stage. Above links are easy mechanism to get yourself noticed, but they did not guarantee that your URL would come at top position in their searches. It all depends on the page rank, locality, back-links, content and several other factors, which guides search engines deciding priority of displaying pages.Let's have a brief of search engine working :- "Search engine have three basic module web crawling, indexing and searching.Web crawler collects information, then it get indexed based on several algorithms and searching retrieves relevant information from this indexed information".
I hope above information would be helpful if you are starting new website and want to to get noticed on internet.




Feb 19, 2010

JUGAAD .... creativity from Northern Rural India

In Feb' 2009 I went to a marriage in Uttar Pradesh near Hathras city. It’s a rural area of Northern India. No malls, no multiplexes, no super bazaars, and no four lane road all things are just as typical like Indian rural areas. But suddenly I noticed one strange thing running on road, its an open engine vehicle having enough space for loading goods. This vehicle had really made a mark in mine memory. By seeing such a strange thing how one can stop himself from asking -"what is this item actually? Why it’s running on road? Is it legal? Is it running with petrol/diesel "?
Pic. I have taken this JUGAAD pic near Hathras.


I started collecting information for this strange vehicle, and my curiosity actually got multiplied when i heard its name, it’s called as "JUGAAD”. Jugaad a typical Hindi word used for making things working in given conditions by hook or crook. Luckily i met a guy who was driving JUGAAD from past 2 yrs. I asked him to tell me about Jugaad, he said "Jugaad comes with a diesel pump engine fixed on a suspension of army jeep chassis and a loading platform at the backside." He had purchased it in nearly 50,000 Rs. Jugaad price can vary between 50,000 - 85,000 Rs as it comes with variation like branded engines and tyres. When i asked him about license of Jugaad, he said "Jugaad has no license, no registration, and no other automobile standards constraint. All are so used to see it that nobody actually objects and to keep away cops we used to bribe them".
Jugaad is really serving many people livelihood in rural areas as they are used for carrying peoples (like city vans, jugaad can be seen carrying 30-35 peoples), loading crops from fields, loading fertilizer, seed and any kind of medium sized load similar to Mini Trucks. With Jugaad one can earn 5000-10,000 Rs per month. In Northern India, it’s one of the cheapest mode for mid size transportation.
Seeing JUGAAD one can’t ignore the creativity coming from rural India. They have very rightly developed a cheap alternate for costly four wheeler options present in Indian Market. On same lines one more name is coming to my mind, which Tata's Nano. It’s also a very creative approach towards making facilities available to common man. Jugaad is an iconic discovery of rural India, which really inspires us to thing radically.
Jugaad teaches us that invention did not need a huge setup, complex equations, sophisticated labs etc... But it needs only simplified and clear thought in right direction.



Feb 18, 2010

Parallel Thinking......A constructive conclusion tool

The approach is called as “Parallel Thinking”.

"Parallel thinking" means that at any moment everyone is looking and thinking in the same direction. There is no attack and defense.

There are six modes of thinking. Each mode is symbolized by a colored “HAT”.








So when the Black Hat is in use, everyone is focusing on possible dangers, weakness faults, etc..
When the Yellow Hat is in use everyone focuses on benefits and values.
The Green Hat is for creativity and new ideas.
The Red Hat is permission to put forward emotions, intuitions and feelings - without any need to justify them.
The Blue Hat is the organizing hat.
The White Hat is on information.

Its ultimate benefits:-

Suppose someone is against an idea being discussed. Normally that person would use every moment and every bit of intellectual energy to point out the faults in the idea.

With the Hat system, that person would be fully encouraged to be cautions under the Black Hat. But when the Yellow hat came around that person would be expected to find values.
If that person was unable to find values while everyone else did find values then that person would be seen by everyone to be "stupid".
If the values are there, why can you not see them ?


Its like human software for formalizing thinking. We can customize it with our need to.


Concept taken from :- "Book:- LATERAL THINKING Author :- EDWARD DE BONO"



What is Blog ? Fun, Money, Passion, Award, Dream

Blog : What exactly blog is ? Blog basically refers to an organized "web logs" i.e. storing any type of data on web any time. This log can be published on internet, to make it visible to desired users.

Lets try to eloborate Blog in a way acronyms does , it can be
Beautiful List of Organized Gesture,
Best Literature of Ordinary Guys,
Blast of Last Opera Group,
Breaking Lines with Oozing Guts,
Building Leagues of Outstanding Gallants,
Blossoming Life by Omitting Grudges.

We can easily map ourself to one of the catogeries from above acronyms. Now lets look at another perspective of blogs, why we should write bolgs. If we try to find answer to this question we would surely get diffrent answers from diffrent people. I ask this question in much simpler way to my friend who is a property broker, he said "i want to make a blog which would help me to attract customers intrested in property". when i asked this question from a techie guy he said "i want blog on technical domain". Then i asked same question to a guy who was searching job , he had not shown much intrest in it and said "if i get a job of blogger then only i would blog". Asked same question from one of my friend who is not working and dont want to be, she said "i want to blog about my dreams". Listening so many thought on one web log is actually the success mantra of blogging. Blog really help one to think about his/her desire which he/she can express without any constraints.

One can blog on anything and most importantly anytime. Like i am doing :).
Lets now check purpose of blogging, it can be for pure Fun , Money, Passion, Dream , Hobby etc....
What i can say here is :- To blog "blog" one should have to blog in a blog way. Its really intresting if thought in construtive way. Word blog can be used as noun or verb, blog word was coined by "Peter Merholz".
Blog is customizably extensible, like one can create collabrative blogs too. Blogs became so much popular nowdays as many communities offers Award to good blogs. Among the major blog awards are The Weblog Awards (Bloggies) , and the BOBs (Best of Blogs). Like usual film or television awarding committees, blog awards are started by a certain body, usually composed of blog enthusiasts.

There are many sites that offer free service and account creation for blogging.
Lets have a look at them :-

Wordpress.com: http://www.wordpress.com/

•Very professional-looking templates, easy to use.
•More limited than others, like Blogger. You can't play with your template.
•You can categorize your posts with custom categories and tags.

Blogger: http://www.blogger.com/

•Lots of easy template integration, custom themes, gadgets, html etc.
•Not perceived to be as professional as Wordpress or some others.
•You can categorize your posts with labels.

LiveJournal: http://www.livejournal.com/

•This is more community-centric blogging, including Friends lists.
•You can categorize your posts with tags as well as your mood, music, etc.

Vox: http://www.vox.com/

•This is more community-centric blogging, including Friends lists.

Xanga: http://www.xanga.com/

•This is more community-centric blogging, including Friends lists.

MySpace: http://www.myspace.com/

•This is more community-centric blogging, including Friends lists.

Facebook: http://www.facebook.com/

•On Facebook, you can have "Notes" which are viewed by your friends.


As we have some basic information about blogs, hopefully term Blog is more releavent now.
So start blogging if you have not started yet and those who have keep Blogging :).



Feb 17, 2010

Starting my "IDITAROD"



IDITAROD: - I
t’s the Dexterous Initiative Towards Aggregating Radical Orientations from Diversity.

Starting my blog with tilted “IDITAROD”, it’s amongst the toughest race on earth. Very motivational and inspiring trial race, every time it shows new Orientations. So, thought to begin with it. If we observe this race, it will surely help us in Dextering our skills.

Let’s take a brief of it; The Iditarod is a dog sled race that takes place every March in Alaska. It is sometimes called the "Last Great Race." Although the race is over 1150 miles long, the race is officially 1,049 miles, since Alaska is the 49th state in the USA. The Iditarod trail goes from Anchorage to Nome. There is a northern route and a southern route; these are used on alternate years (north in even-numbered years). The race starts on the first Saturday in March and takes about 10 days to complete. The winning musher (dog sled racer) takes home a large cash prize; the last musher to finish the race extinguishes (and wins) a red lantern at the finish line.


This race can be easily mapped to our life. If we sketch all phases of this event we can easily draw out many constructive conclusions, which will serve us in various practical situations. I really liked the challenges observed in this event. It’s not just physical challenge but it test mental level to the last extend.


Most of the times we give excuses, not able to think because environment is not good or its
noisy, clumsy etc...But people who participate defines their strategy at runtime despite of extreme conditions, they are really like Martians. Extreme conditions of this trial include freezing temperature, which can easily cause frost nip and even frost bite in simplified term it’s like losing skin sensation and skin live cell destruction. These are situations in which the body has made the decision to risk or sacrifice some of the more expendable regions to preserve the core temperature and so avoid death from hypothermia. Huh it’s really tough.But a real applaud to all the mushers for their die-hard effort.Normal person can think only of his or her survival in such scenarios whereas mushers compete there. At last i want to mention one famous quote to end this, which goes like :-






"Some are born great, some achieve greatness, and some have greatness thrust upon 'em"


Starting my "IDITAROD" :) ......