Theory
invisible supervisor
બે lessons row માં same doorstep પર ended થયા છે: કંઈક assembly ને load કરે છે, કંઈક JIT ને run કરે છે, કંઈક garbage ને collect કરે છે. time to name and tour that something.
Common Language Runtime એ .NET નો part છે જે actually PRESENT છે જ્યારે ShopKeeper Mehta Stores પર runs કરે છે: તમારું code ક્યારેય alone execute નથી થતું, તે CLR ની અંદર execute થાય છે, જેમ BCA403 program JVM ની અંદર execute થતું હતું.
supervisor આખો day શું exactly કરે છે? છ jobs.
Theory
control tower
airport tower planes ને fly નથી કરતું. તે દરેક ને takeoff માટે clear કરે છે (verification), runways assign કરે છે (memory), દરેક movement ને watch કરે છે (execution management), emergencies ને procedure દ્વારા handle કરે છે (exceptions), અને દરેક airline ને alike treat કરે છે: Air India કે Indigo, same rules.
CLR એ tower છે. VB.NET planes, C# planes: એકવાર તેઓ MSIL હોય, tower કહી પણ નથી શકતું કે કઈ language એમને build કર્યા, અને all ને identically supervise કરે છે. એ word common છે જે તેનું work કરે છે.
Theory
CLR ના 6 services
આને list તરીકે learn કરો; exams exactly આ માટે ask કરે છે:
- Loading: program જેમ જેમ assemblies ને need કરે તેમ તેમ તેમને finds અને loads કરે છે
- Verification: run કરતા પહેલા MSIL ને type safety માટે checks કરે છે (કોઈ stray memory tricks sneak through નથી)
- JIT compilation: MSIL થી native, method by method (last lesson)
- Garbage collection: automatic memory management
- Security: enforce કરે છે કે loaded code શું કરવા allowed છે
- Exception handling: એક structured crash-handling system across all languages, Unit 3 ના Try/Catch ની નીચે machinery
At a glance
CLR service, અને ShopKeeper શું gets કરે છે
| Service | શું ShopKeeper gets કરે છે |
|---|---|
| Loading | તેની assemblies on demand found અને brought in થાય છે |
| Verification | Corrupt અથવા unsafe MSIL ને run થતા પહેલા refused કરવામાં આવે છે |
| JIT | till પાસે જે પણ CPU હોય તેના પર native speed |
| Garbage collection | ભૂલેલા cleanup થી કોઈ memory leaks નહીં |
| Security | Downloaded plugins disk ને wipe નથી કરી શકતા |
| Exception handling | price માં typo message box ને crash કરે છે, till ને નહીં |
Quiz
runtime ને COMMON Language Runtime શા માટે કહેવામાં આવે છે?
- કારણ કે તે સૌથી commonly installed Microsoft product છે
- કારણ કે દરેક .NET language નું code આ એક shared runtime પર runs કરે છે
- કારણ કે તે ફક્ત commonly used, pre-approved programs ને runs કરે છે
- કારણ કે તે Windows અને Java programs વચ્ચે shared છે
Show the answer
કારણ કે દરેક .NET language નું code આ એક shared runtime પર runs કરે છે
Common નો અર્થ છે LANGUAGES આરપાર shared: VB.NET, C# અને F# બધા MSIL માં compile થાય છે, અને CLR result ને identically supervise કરે છે, CTS ના shared type system દ્વારા aided. MSIL stage પર, runtime કહી શકતું નથી કે કઈ language એ code ને લખ્યું. Option A popularity ને name સાથે mistakes કરે છે. Option C approval process ને invent કરે છે. Option D too far stretches કરે છે: Java JVM પર runs કરે છે; 2 runtimes parallel designs છે, shared infrastructure નહીં.
Think first
જ્યાં verification તેનું keep earn કરે છે
CLR MSIL ને run કરતા પહેલા verify કરે છે. BCA104 ના C ને think કરો, જ્યાં program કોઈ પણ pointer થી કોઈ પણ address પર write કરી શકતું હતું. verification કયા class ના disaster પર door close કરે છે?
Show the answer
Memory corruption અને તેના exploits. C માં, stray અથવા malicious pointer બીજા variables, બીજા programs ના data ને overwrite કરી શકતો હતો, even code inject કરી શકતો હતો: best પર crashes, worst પર viruses. Verification prove કરે છે કે MSIL ફક્ત types અને memory ને touch કરે છે જે તે legitimately owns છે BEFORE એક પણ instruction runs; unverifiable code ને refused કરવામાં આવે છે. managed VB.NET માં no raw pointers સાથે combine કરીને, BCA104-era bugs ના whole categories અહીં simply impossible છે, same safety pitch જે Java એ BCA403 માં made કર્યું હતું.
Watch out
boxes ને straight રાખો
CLR vs JIT: JIT એ CLR ની અંદર એક component છે, synonym નહીં તેના માટે. "The JIT manages memory" બે વાર wrong છે.
CLR vs class library: CLR એ engine છે; library એ parts છે. engine code ને run કરે છે; તે TextBox provide નથી કરતું.
CLR vs CTS/CLS: CTS એ shared type rulebook છે, CLS interop guidelines છે; CLR એ running software છે જે rules ને enforce કરે છે.
Theory
Same exam, બે vocabularies
આ lesson ને BCA403 ના JVM lesson ની બાજુમાં set કરો અને parallel almost line for line છે: load, verify, JIT, collect garbage. Two honest differences worth writing જ્યારે compare કરવા માટે asked થાય: CLR ને day 1 થી MANY languages માટે design કરવામાં આવ્યું હતું (JVM originally Java alone માટે), અને classic .NET એ એક OS ને target કર્યું જ્યારે Java ઘણા ને target કર્યું. engine toured થયા પછી, next lesson બીજા pillar ને open કરે છે: class library જેમાંથી ShopKeeper assembled થશે.
Summary
Key takeaways
- CLR એ .NET નું execution engine છે: દરેક managed program તેની અંદર runs કરે છે.
- છ services: loading, MSIL verification, JIT compilation, garbage collection, security, exception handling.
- Common = all .NET languages માટે one runtime; MSIL level પર language disappear થાય છે.
- Verification execution પહેલા type safety ને check કરે છે: unsafe code ને refused કરવામાં આવે છે, crashed નહીં.
- JIT અને GC CLR ની અંદર components છે, તેના alternatives નહીં.
- CLR : .NET :: JVM : Java, multi-language support સાથે .NET નો day-1 difference તરીકે.
- Memory hook: control tower કંઈ fly નથી કરતું, everything ને supervise કરે છે.