Friday 7 October 2011

A C++ teaser

I would like you to provide plausible explanation about why garbage data is generated in the following scenario

I need to generate a data block of size 4096 bytes for internal usage in my program. So the code I adopted from my project sample was
Output Generated:
data size generated:4102
data generated: !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|} !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUú ¶ hh


I have run the loop only 4096 times, then from where did last six garbage bytes come from? Even the data size had been allocated to be only 4096 bytes. How is it able to accommodate more bytes than allotted?

If I remove the comment marks on sixth line, I get a data block of size exactly 4096 bytes and no garbage generated/appended at last of the data block.
Why it happens?

Monday 3 October 2011

Function Vs Method


Briefly explain the difference between a function and method?

“Cool, till now I thought both were synonyms” – My first reaction to this question when it was posed to me at one of the written test. You would be surprised to know that both are different and wonder why it didn’t occur to you in your long innings of programming. Do not worry; many are sailing in the same boat. Let us rescue us all through this discussion.

We have seen the concept of functions in ‘C’, methods in ‘JAVA’ and both in ‘C++’. This might ring a bell in your head. Yes, it’s correct; it has something to do with OO concepts. Through googling, I came to an understanding that,

Methods are dependent on the object. They can be invoked using the object i.e. object is an implicit parameter for method. They can access the member variables of the object.  So the calls to the method can return different values based upon the object invoking it.

Whereas functions is independent of the calling object. They can access only local variables, global variables and constants.  Hence, calls to a function with same parameters will return same value.

 Let us understand with simpler example, consider lion and deer as two objects, both can perform the function of sleep, but only lion can invoke the method of roar!






Now an interesting issue of classifying static method arises. Can it be called a function? Yes, to my understanding it can also be called a function as it shares its traits being independent of object and returning values upon being called.

You can find more information from this interesting discussion. So next time, do not miss to differentiate a function from a method.

Picture Source: Internet

Thursday 22 September 2011

Blotted out the sun!!!


Persian: " A thousand nations of the Persian empire descend upon you. Our arrows will blot out the sun!"

When I saw the subsequent scene in the film 300, I was mesmerized. Today it was brought on again when UCI reclaimed the world dodge ball record.




This mega social event during the very first week of the Fall quarter at the university gave us – the new international graduate students an opportunity to experience the vivacious student life at UCI campus. There were only two colors – blue and yellow visible in this unified multi-cultural Eater nation. The soft balls were fired in unison by both the teams soaring high in the air spreading the message of brotherhood. Fuel cells of the participants were kept full to brim, thanks to the Live music, cheer leader performance, rockstar energy drinks, mouthwatering food sold by student organizations and the enthusiasm in the air. It was a moment of proud for me and other 4000+ fellow UCI students that this attempt had created a new world Guinness record. You can re-live this record at here.


Thanks to UCI, and its co-sponsors for organizing such electrifying event. Raring to go Zot, zot and zot again!!!







Tuesday 13 September 2011

Stay Hungry, Stay Foolish

                                                                                                                                                                         – As quoted by Steve Jobs & The whole earth catalog


 
              I still remember the days when I felt a thirst to further expand my knowledge, strengthen my basics and turn out as a contributing person to the field. I saw many of my friends appearing for GRE exams, applying for overseas college and flying to various parts of the world. At that time, I felt that it wasn’t my cup of tea, though I yearned for it. Many people discouraged the very idea giving reasons from recession to racial discrimination. Your strengths are better known to your friends than you and so did my friends. They encouraged me to go for it by explaining the complexities and rewards involved in it. In a puzzle when you identify one piece’s position, others fall into their place with ease. I got sufficient guidance from my tutors, support from mother & relatives. With these I embarked on the mission in full swing and now I have landed in this new country where many dreams have been fructified after a yearlong hard work. It was also a rewarding experience for me as it turned out to be a crash course to learn the complexities involved in Indian Banking system, like mortgaging, legal opinion, property evaluation, power of attorney, property registration, tax filing are few to be named. Running from one office to other, filling innumerable application forms, reading various rules and regulations, reaching out to reluctantly reticent government officials, preparing umpteen numbers of plans and to do lists tested mine and my mother’s nerve strength. I hope they have hardened me enough to face the new challenges and softened enough to accept new changes. I feel confident enough to guide others on the same path and help them fulfill their ambition too.   

At this moment I must thank all the above persons who played an important in role in my securing a graduate admission at University of California, Irvine. I learnt in my childhood that I can be outnumbered, but never I should become outgeneralled. With this thought in my mind, I intend to remain hungry for knowledge, explore all paths by starting as a foolish and finally evolve as a source of light. In this journey, I seek blessing from my Guru –SAI, my mother and my tutors to travel in the right direction. I request support from my friends to travel at right speed. 

Stay in touch.