0% found this document useful (0 votes)
41 views

Introduction To

The .NET Framework provides a common language runtime (CLR) that manages code execution. The CLR compiles code to Microsoft intermediate language (MSIL) and metadata. It then uses just-in-time (JIT) compilation to convert MSIL to native machine code as needed. Assemblies contain MSIL and metadata and are the fundamental units for deploying .NET applications. The CLR also provides memory management, security, and other services to managed code applications.

Uploaded by

Samia sultana
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Introduction To

The .NET Framework provides a common language runtime (CLR) that manages code execution. The CLR compiles code to Microsoft intermediate language (MSIL) and metadata. It then uses just-in-time (JIT) compilation to convert MSIL to native machine code as needed. Assemblies contain MSIL and metadata and are the fundamental units for deploying .NET applications. The CLR also provides memory management, security, and other services to managed code applications.

Uploaded by

Samia sultana
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 48

Visual Programming

UIIT
PMAS Arid Agriculture University, Rawalpindi

Course Instructor: Suleman Khurram


1
Aim of the course
• Apparent:
– Developing a practical knowledge of VP
– C#, the language
– ASP Web development
– .Net framework
• Furthermore:
– Refine your understanding of OOP
– Learn how to learn another programming language
– Be a better programmer in general (hopefully!)

2
Distribution - Tentative
• Grades breakdown: according to UIIT rules
• Assignments and Quizzes
• Midterm and Final
• Project details will be out at the halfway mark
‒ Groups of 3-4
‒ Propose a project idea, write a brief specification
‒ Implement it and present to the class

3
Programming

4
Programming
• Telling a computer how to do certain things by giving it
instructions.
• Two main steps:
‒ Algorithm design
‒ Coding

• Requirements:
‒ A machine
‒ A set of tools
‒ A compiler
‒ And of course, a programming language

5
Programming language
• Written language that tells the computer what to do in
order to solve a problem.
• Programming paradigms:
‒ Imperative: Programmer instructs how to change the state
‒ Declarative: Programmer tells only the required results but not how to
compute it.
‒ Object-Oriented: Based on concept of objects which may contain data (as
fields or attributes) and code (as methods).
Objects can communicate with each other.
C# provides full support for object-oriented programming.

6
Algorithms and Data Structures
• Algorithm: a procedure for solving a problem or computing
something.
– sorting: putting data in ordered form
– searching: finding data in some kind of index
– finding primes and generating random numbers
– graphics: drawing lines, arcs, and other geometric objects
• Data structure: a way to store data.
– arrays
– linked lists
– Stacks
Data Structures organize the data and algorithm use that
organization.

7
Introduction to .Net
Framework

8
Overview
• The .NET Framework is a technology that supports building
and running the next generation of apps on the internet, on
the desktop and on mobile devices.
‒ To provide a consistent object-oriented programming environment whether:
◦ object code is stored and executed locally
◦ executed locally but Internet-distributed, or
◦ executed remotely

‒ To provide a code-execution environment that minimizes versioning conflicts


(“DLL Hell”) that was a big problem previously.

‒ To provide a portable environment based on certified standards, C# and a


major part of the .NET runtime: the Common Language Infrastructure (CLI)
that can be hosted by any operating system.

9
Influences
• .Net is the result of many influences.

10
Multi-language framework
• .Net not only supports C# but it also supports VB, C++, J#.

Code. vb Code. cs Code. cpp

Development tools
and environment

App.exe

11
.Net is cross platform
• Compiled .Net app can run on any supported platform

App.exe

Win 64 Win 32 Win CE

12
.Net is cross-platform
• Cross-platform execution realized in two ways:
– Apps are written against Framework Class Library (FCL), not
underlying OS
– Compilers generate generic assembly language which must be
executed by the Common Language Runtime (CLR)
• Framework Class Library
‒ 1000's of predefined classes
‒ common subset across all platforms & languages
‒ networking, database access, XML processing, GUI, Web, etc.
‒ Goal? FCL is a portable

13
.Net architecture
VB VC++ VC# JScript … Common Language

Specification

Visual Studio.NET
ASP.NET: Web Windows
Services and Web Forms
Forms
ADO.NET: Data and XML
Base Class Library

Common Language Runtime

14
Base Class Library (BCL)
• Has classes for IO, threading, database, text, graphics,
console, sockets/web/mail, security, cryptography, COM,
run-time type discovery/invocation, assembly generation.
• Similar to Java’s System namespace.

15
Base Class Library (BCL)

16
Common Language Runtime (CLR)
• The common language runtime (CLR) is the engine that runs
and “manages” executing code.

• It is a virtual machine like component which runs over the


machine to execute .net code.

• The CLR supports many different languages and targets on


these features:
– Compilation and Verification
– Security
– Memory Management

17
CLR – Compilation and Verification
• It is responsible for :
– Building Managed Code: The Common Type System (CTS)
– Compiling Managed Code: MSIL and Metadata
– Organizing Managed Code: Assemblies
– Executing Managed Code : JIT compilation

18
CLR – Common Type System (CTS)
• Common Type System (CTS) is a standard that specifies
how type definitions and specific values of types are
represented in computer memory (e.g. short and int in C# maps
to Int16 and Int32 in .Net).

• A type can be described as a definition of a set of values (e.g.


int), and the allowable operations on those values (e.g. addition).
• .

• Common Language Specification (CLS) is a set of specifications


that language and library designers need to follow
– This will ensure interoperability between languages

19
CLR – MSIL and Metadata
• Managed code is the code written using .Net.
• When a managed code is compiled, two things are produced:
– Code in Microsoft Intermediate Language (MSIL).
– Metadata, information about those instructions and the data they
manipulate.

• Both the MSIL and the metadata are stored in a standard


Window portable executable (PE) file. This file can be
either a DLL or an EXE, and generally called module.

20
CLR – MSIL and Metadata
• Microsoft Intermediate Language (MSIL) is a CPU-
independent set of instructions that can be efficiently
converted to the native code.

• Metadata is data that describes the state of the managed


code and a detailed description of each type and attribute
within the managed code. Stored in the same file as MSIL.

21
CLR - Assemblies
• An assembly or an executable or a DLL compiled using one of
the .Net Framework’s many language compilers.

• Assemblies contains the code that the runtime executes in the


form of MSIL, also contains the metadata called manifest.

• An assembly manifest contains all the metadata needed to


specify assembly’s version requirements, locating information
for classes and information about security.

22
CLR - JIT
• All the Microsoft .NET languages are converted to CPU
independent intermediate language (not the machine language)
by compiler.

• CLR then converts that IL to machine code using Just-In-Time


(JIT) compiler. Just-In-Time means it is done as soon as the
recompilation subroutine is called.

• The JIT code stays in memory for subsequent calls. If memory


becomes low, this code is then discarded.

23
CLR - JIT
• When a method is JIT compiled, it’s also check for type
safety, This process, called verification.

• Only those methods will be compiled that get called.


– If a method in an assembly is loaded but never used, it will stay in
its MSIL form.
– Compiled code is not saved on disk, JIT compilation is carried out
each time an assembly is loaded

24
CLR - JIT

25
Types of JIT Compilers

26
Types of JIT Compilers
• In Microsoft .NET there are three types of JIT compilers:
– Pre-JIT :- compiles complete source code into native code in a
single compilation cycle. This is done at the time of
deployment of the application.
– Econo-JIT :- compiles only those methods that are called at
runtime. However, these compiled methods are removed
when they are not required.

27
Types of JIT Compilers
‒ Normal-JIT :- compiles only those methods that are called at
runtime. These methods are compiled the first time they are
called, and then they are stored in cache. When the same
methods are called again, the compiled code from cache is used
for execution.

28
CLR- Security
• When compiling MSIL to native code, code must pass a
verification process.
• Verification examines MSIL and metadata to find out
whether the code is type safe.
• The CLR implements two different types of security for
assemblies: code access and role-based security

29
CLR- Security

CAS – Controls what Based on the user who is


code can do on the executing the code
computer

30
Memory Management
• Program Objects/Data occupy memory
• How does the runtime system efficiently create and
recycle memory on behalf of the program?

31
Dynamic memory allocation and
reclamation
• Heap contains dynamically allocated objects
• Object allocation: malloc, new
• Deallocation:
– Manual/explicit: free, delete
– Automatic: garbage collection

32
Dynamic memory allocation and
reclamation

33
Explicit Memory Management
• More code to maintain
• Efficiency can be very high
• Gives programmers “control”

34
Garbage Collection - Automatic memory
management
• Reduces programmer burden
• Eliminates sources of errors
• Integral to modern object-oriented languages, i.e., Java,
C#, VB.Net etc.
• Challenge:
‒ performance efficiency

35
Key Issues For Memory Management
• For both (Automatic And Explicit)
– Fast allocation
– Fast reclamation
– Low fragmentation (wasted space)
– How to organize the memory space
• Garbage Collection
– Discriminating live objects and garbage

36
CLR- Memory Management
• Objects are automatically freed from the managed heap
when they are no longer required by the application.
‒ Garbage Collection

37
CLR- Memory Management
• Garbage Collection
– Every instance of a reference type is allocated on the heap. As
the application runs, the memory allotted to the heap fills up.
Before new instances can be created, more space must be
made available. The process of doing this is called garbage
collection.
– When CLR notices that the heap is full, it will automatically run
the garbage collector.
– Garbage objects can appear anywhere in the heap.
– Garbage collection can reposition the contents of the heap.
– The garbage collection view objects in generations.

38
GC- Generations
• Is a feature of GC that enhances its performance
• There are 3 Generations.
• Generations 0:
– When an object is initialized, its in generation 0. These are new
objects that have never been played around by the GC.
– As and when more objects get created, the process of Garbage
Collection is invoked by the CLR.

39
GC- Generations
• Generation 1:
– The objects that survives the garbage collection process are
considered to be in generation 1.
– These are the old objects
• Generation 2:
– As more new objects get created and added to the memory,
the new objects are added to generation 0, generation 1 old
objects become older, and so are considered to be in
generation 2.

40
GC- Generations
• Generation 2 is the highest level generation in the
garbage collection process.
• Any further garbage collection process occurring causes
the level 1 objects promoted to level 2, and the level 2
objects stay in level 2 itself, as this level is the highest.
• This process helps in categorizing the memory
heap as to where the de-allocation needs to be done
first and where next.

41
GC- Generations

42
GC- Techniques
• Reference Counting
• Tracing
‒ Mark-sweep
‒ Mark-compact

43
GC: Reference Counting
• A Reference Count for each object
‒ No of incoming pointers
‒ Incremental
‒ Count = 0 (unreachable, considered garbage)
• Concerns
‒ Space for reference count
‒ Efficiency (Reference count adjustments)

44
GC: Mark-Sweep
• How it works
‒ Tracing to “mark” live objects
‒ Sweep to reclaim dead or “unmarked ”objects
‒ Marked status set to Unmarked for subsequent invocations of
algorithms
• Concerns
‒ Fragmentation
‒ Cost proportional to heap size
‒ The normal program execution may get suspended while this
algorithm runs.

45
GC: Mark-Compact
• How it works
‒ Tracing to “mark” live (reachable) objects
‒ Compacts the heap by moving all live objects into contiguous
memory locations
‒ The memory left unused after compaction is recycled
• Concerns
‒ Fragmentation solved
‒ Cost - Multiple scans of live objects

46
Xamarin

47
Xamarin
• Bringing open source .NET to mobile development, enabling every
developer to build truly native apps for any device in C# and F#.

• Providing native app for Apple iOS, Google Android, and Microsoft
Windows smartphones forces you to write three different apps using
three different languages.

• Xamarin comes handy here.

• Building app using single programming language (C# or F#) using .net
framework.

48

You might also like