marq

Dr. Charles Simonyi is the Father of Modern Microsoft Excel                                           JavaScript was originally developed by Brendan Eich of Netscape under the name Mocha, later LiveScript, and finally renamed to JavaScript.                                           The word "Biology" is firstly used by Lamarck and Treviranus                                           Hippocrates (460-370 bc) is known as father of medicine.                                           Galene, 130-200 is known as father of Experimental Physology                                           Aristotle (384-322 BC) is known as Father of Zoology because he wrote the construction and behavior of different animals in his book "Historia animalium"                                           Theophrastus(370-285 BC) is known as father of Botany because he wrote about 500 different plants in his book "Historia Plantarum".                                           John Resig is known as Father of Jquery -                                          HTML is a markup language which is use to design web pages. It was invented in 1990 by Tim Berners-Lee.                                                                The Google was founded by Larry Page and Sergey Brin.                                                                Rasmus Lerdorf was the original creator of PHP. It was first released in 1995.                                                               Facebook was founded by Mark Zuckerberg                                                               Bjarne Stroustrup, creator of C++.                                                                Dennis Ritchie creator of C                                                                                                                              James Gosling, also known as the "Father of Java"                                          At 11.44%, Bihar is India's fastest growing state                                          Father of HTML -Tim Berners Lee                                          orkut was created by Orkut Büyükkökten, a Turkish software engineer                    Photoshop: It came about after Thomas Knoll, a PhD student at the University of Michigan created a program to display grayscale images on a monochrome monitor which at the time was called 'Display'.

Late Binding

आप सोंच सकते हैं कि Compiler एक ही प्रकार के Statement के Response में ये कैसे तय करता है कि उसे किस Class के Member Function को Execute करना है?

पहले उदाहरण में हमने देखा कि Compiler हमेंशा Base Class के Member Function को ही Execute करता है। लेकिन दूसरे उदाहरण में Compiler को ये पता नहीं होता है कि Pointer ptr में किस Class के Object का Address है। इसमें DerivedClass1 के Object का भी Address हो सकता है और DerivedClass2 के Object का भी। इसलिए Compiler Compile Time में ये तय नहीं कर पाता है, कि उसे किस Class के Member Function को Execute करना है। इसलिए Compiler Compile Time में किसी प्रकार का निर्णय नहीं लेता बल्कि Program के Run Time में ये तय करता है कि उसे किस Class के Member Function को Execute करना है।

Program के Run Time में जब Function Call Execute होता है, तब Compiler Object ptr में Stored Address के आधार पर ये पता लगाता है कि Pointer ptr में किस Class के Object का Address है। Object की Class के आधार पर ही Compiler DerivedClass1 :: show() Function को Execute करता है या DerivedClass2 :: show() को Execute करता है।

इस प्रकार से किसी Object के Reference में Call किए गए किसी Function को किस Class से Execute करना है, जब इसका निर्णय Compiler Program के Run Time में लेता है, तब इस प्रक्रिया को Late Binding या Dynamic Binding कहते हैं। Function Call को Appropriate Function से Connect करना Binding कहलाता है। जब Function Normal Way में Compilation के दौरान Function Call से Connect होता है, तो इस प्रक्रिया को Static Binding या Early Binding कहते हैं। Late Binding में Early Binding की तुलना में लगभग 10% अधिक समय लगता है लेकिन Late Binding से Program की Flexibility व Power कई गुना बढ जाती है।

एक ऐसा सामान्य Object जिसकी Class का Member Function Virtual नहीं होता है, वह Object जब Memory में Store होता है, तब उस Object में केवल उसी के Data होते हैं। जब उस Object के लिए कोई Member Function Call किया जाता है, तब Compiler उस Object के Address को उसके Member Function में Pass कर देता है। Object का ये Address उस Object के Member Function में this Pointer में Store हो जाता है।

इस this Pointer में Stored Object के Pointer का प्रयोग Member Function Object के Data को Invisibly Access व Manipulate करने के लिए करता है। किसी Object के लिए जितनी बार भी कोई Member Function Invoke होता है, उतनी ही बार यानी हर बार Compiler उस Object के Address को Call हो रहे Member Function के this Pointer में Store कर देता है। ये this Pointer Object में Store नहीं होता है और ना ही किसी प्रकार की कोई Memory लेता है। this Pointer ही Object व उसके Normal Member Function के बीच का एक जरूरी Connection होता है।

लेकिन जब हम Virtual Functions के बारे में बात करते हैं, तब थोडी जटिलता आ जाती है। जब किसी Virtual Member Function वाली Class से कोई अन्य Class Derive की जाती है, तब Compiler एक Array के रूप में एक Functions के Addresses की एक Table Create करता है, जिसे Virtual Table कहते हैं। अलग-अलग Compilers के आधार पर इस Virtual Table को vtable या vtbl कहते हैं।

हमारे दूसरे उदाहरण में DerivedClass1 व DerivedClass2 दोनों Classes में उनके स्वयं के Virtual Tables हैं। Class के हर Virtual Function की Entry उस Class की हर Virtual Table में होती है। चूंकि DerivedClass1 व DerivedClass2 दोनों ही Classes BaseClass से Derived हैं, इसलिए इन दोनों ही Classes की Virtual Table में Same Virtual Function की Entry होती है और सभी Entries का क्रम भी दोनों Tables में एक समान होता है। लेकिन दोनों Classes के लिए Tables के Addresses भिन्न होते हैं।

DerivedClass1 व DerivedClass2 के जितने भी Objects Create होते हैं, उन सभी में उनके Data के अलावा एक Extra Pointer होता है। ये तथ्य उन सभी Objects पर लागू होता है, जिनकी Class में एक या एक से अधिक Virtual Functions होते हैं। इस Pointer को vptr या vpointer कहते हैं। इस Pointer में उसकी Class के Virtual Table का Address होता है। इसलिए वे Objects जिनकी Class में Virtual Functions होते हैं, सामान्य Objects की तुलना में Size में थोडे बडे होते हैं।

हमारे उदाहरण के आधार पर जब एक Virtual Function Call होता है, तब Compiler ये तय नहीं करता कि उसे किस Class के Member Function को Call करना है बल्कि Compiler ऐसे Codes Create करता है, जो सबसे पहले Object के vptr के Content को Check करता है क्योंकि इसमें Class के vtable का Address होता है। फिर vptr के आधार पर Compiler Class के vtable को प्राप्त करता है और उस vtable के Member Functions के Addresses की List में से Appropriate Member Function के Address को Choose करके उस Member Function को Execute कर देता है। परिणाम स्वरूप जब हम Virtual Functions की बात करते हैं, तब Object ये तय करता है कि उसे किस Member Function को Call करना है ना कि Compiler ये तय करता है कि Object के लिए किस Member Function को Call करना है।

हमने जो पिछले दोनों उदाहरण देखे हैं, वे Realistic नहीं हैं। हमने इन दोनों उदाहरण Programs में जो Virtual Functions वाले Standalone “Pointers to Objects”Variables Create किए हैं, वास्तव में वे Standalone Create नहीं होते हैं बल्कि एक Array में Create होते हैं। हमारा अगला उदाहरण अधिक Realistic Situation पर आधारित है।

No comments:

Post a Comment