Net Framework Part - II - Created By: Asst. Prof. Ashish Shah, J.M.Patel College of Commerce

Page created by Emily Schneider
 
CONTINUE READING
.Net
 Net Framework

   Part - II

           Created By: Asst. Prof. Ashish Shah, J.M.Patel
                      College of Commerce                   1
Benefits of .Net

„   Simplify
        p y the application
                  pp         development
                                      p     :
    ‰ There are several limitation with current developments

      tools and techs that reduce developers productivity.
    ‰ Development should become easier because the

      .NET Framework provides a new set of tools, including
      a large set of object oriented, extensible system-level
                                                  system level
      classes.
    ‰ The .NET framework brings the power of the os.

      Whi h iis much
      Which          h closer
                        l     tto th
                                  the d
                                      developer,
                                          l      th
                                                 through
                                                       h a rich
                                                            i h
      set of classes and services that are more easily
      accessible than anyy pprevious windows-based set of
      APIs.
                     Created By: Asst. Prof. Ashish Shah, J.M.Patel
                                College of Commerce                   2
Benefits of .Net

„   The .Net framework simplifies development in the
    long term.
„   Application Development are subject to the familiar
    headaches of “DLL hell” that arise when component
    registrations get corrupted or type library versions
    get mixed upup.
„   The .net Framework overcomes these deployment
    limitations by making components self-describing
                                        self describing
    through metadata, so removing the need for GUID-
    based registration.

                   Created By: Asst. Prof. Ashish Shah, J.M.Patel
                              College of Commerce                   3
Benefits of .Net

„   XML Everywhere
               y       : .Net framework introduces XML
    into every aspect of software development.
„   XML is common communication technology in
    information in .net.
                    net
„   It is used as basis for a number of xml based
    grammars that describe the limitation in the .net .
    g
„   A grammar refers to a collection of fixed tags that
    combine to describe a specific object or entity.
„   S XML provides
    So            id a unified
                            ifi d system
                                     t   ffor sharing
                                               h i d  data
                                                        t
    within the .Net framework and between components
    built using
              g .net.
                    Created By: Asst. Prof. Ashish Shah, J.M.Patel
                               College of Commerce                   4
Benefits of .Net

„   UDA : It stands for Universal Data Access
                                       Access.
    In case of .Net UDA means that ability to
    access data anytime
                 anytime, anywhere
                          anywhere, regardless
    of what device is used.

                 Created By: Asst. Prof. Ashish Shah, J.M.Patel
                            College of Commerce                   5
Highlights of .Net Framework

„    The .Net Framework is made of layered,
                                          y      constituent
     parts that provide the services, classes and tools that
     work together to provide the .Net development
     p
     platform.
„    The high-level layers of .net framework are :
1)   CLR : It provides reliable, secure execution envt and
     supports multiple programming langs
                                       langs.
2)   Class Library : It provides set of factored, extensible
     classes that area are used across all .Net complaint
     langs.
3)   Lang. and development tools : familiar langs. Such as
     c++, vb and jjavascript
                           p are overhauled in .Net feature
     sets are greatly.
                    Created By: Asst. Prof. Ashish Shah, J.M.Patel
                               College of Commerce                   6
Highlights of .Net Framework

„   The .Net
          Net frame work is layered into
    increasingly abstracted levels of functionality.
„   At the base of the framework CLR is present
    provides the core managed execution envt.
    that runs all .Net assembly code.
„   Next comes the class libraries which abstract
    system level functionality into a set of
    extensible classes the implement the
      pp
    application  code.
                  Created By: Asst. Prof. Ashish Shah, J.M.Patel
                             College of Commerce                   7
Highlights of .Net Framework

„    Class Libraries :
1)   The .net framework classes are similar in
     concept to MFC namely they provide
     developers with access to a wide range of
     system services without having to do a lot
     coding.
2)   The framework classes are organized into
     namespaces, which organize classes into
     hierarchical structure of related groups.
                                       g p
                 Created By: Asst. Prof. Ashish Shah, J.M.Patel
                            College of Commerce                   8
Highlights of .Net Framework

„   Framework classes save developers time
    and effort, bcoz they provide an excellent
    level of encapsulation
                  p         support
                               pp for windows
    system functionally.
„   The .Net framework provides classes at
    different levels of abstraction.
„   At the lowest level,
                   level the base class library
    provides a set of classes that give easy
    access to windows API functionalilty.y
                 Created By: Asst. Prof. Ashish Shah, J.M.Patel
                            College of Commerce                   9
Compilers of .NET FRAMEWORK

„    There are 2 types of compilers:
1)   JIT compiler : it is known as just in time compile. It
     is an optimized compilers that analyzes MSIL and
     convert it to native code as needed.
2)   Traditional Compiler : The assembly is entirely
     converted
            t d into
                 i t native
                         ti code
                               d and d lloads
                                           d single
                                               i l
     instruction set. Traditional compilers are less
     optimized than JIT compilers, bcoz, they must be
     compiling an entire assembly all at once, rather
     than the parts that executed.

                    Created By: Asst. Prof. Ashish Shah, J.M.Patel
                               College of Commerce                   10
Primitive Data Types in .Net :

„    Primitive Data Types supported by compiler
    and are located in the root system
    namespace.
            p
„   The table below shows a selection of the
    most common primitive types.

                 Created By: Asst. Prof. Ashish Shah, J.M.Patel
                            College of Commerce                   11
Name in     CLS Type                      Name in                  Description
MSIL                                      Class
Assembler                                 Library
(CTS)                                     (
                                          (SYSTEM.)
                                                  )
BOOL        Yes                           Bool                     True/false
                                                                   value
Char        Yes                           Char                     Unicode 16
                                                                   bit char
Class       Yes                           Object                   Object string
Float32     Yes                           Single                   32 bit float
Float64     Yes                           Double                   64 bit float
Int8        No                            SByte                    Signed 8 bit
                                                                   integer
                  Created By: Asst. Prof. Ashish Shah, J.M.Patel
                             College of Commerce                                 12
Int16        Yes                            Int16                Signed 16
                                                                 bit iinteger
                                                                        t

Typedref     No                             TypedRefer- Pointer +
                                            ence        runtime type
Unsigned int8 Yes                           Byte                 Unsigned 8
                                                                 bit integer
Unsigned     Yes                            Uint16               Unsigned 16
int16                                                            bit integer
                Created By: Asst. Prof. Ashish Shah, J.M.Patel
                           College of Commerce                                  13
Garbage collection Algo.

„   The basic ggoal of g garbage
                              g collection is to look
    for objects that are not being used by an
    application.
„   T be
    To  b more technical,
                      h i l objects
                              bj     that
                                      h are not
    referenced by code within the application can be
    cleaned up
             up.
„   During the cleaned up process :
    * An object
         object’ss finalize
                      a e method
                             et od is
                                    s ca
                                      called.
                                          ed
      Finalize method is written by the developer and
    provides object specific cleanup code.
                  Created By: Asst. Prof. Ashish Shah, J.M.Patel
                             College of Commerce                   14
Garbage collection Algo.

Finalized method conti…
  The memory associated with the object is
  reclaimed. The trick to ggarbage
                                g collection is to
  determine which objects are not referenced.
  To determine this,, the garbage
                          g    g collection algo
                                               g
  traverses active objects within an application.
  To determine what objects are active or
  referenced following rules are used :

                 Created By: Asst. Prof. Ashish Shah, J.M.Patel
                            College of Commerce                   15
Garbage collection Algo.

1)    All object contained on a thread’s
                                 thread s stack are
      referenced, as are the objects they contain.
2))   All g
          global objects
                    j     and the object
                                     j   theyy contain
      are referenced. Static object also considered
      to be global and are hence part of this root.
3)    All objects referred to by the cpu’s registers
      are referenced, as are the objects they
      contain.
             i

                   Created By: Asst. Prof. Ashish Shah, J.M.Patel
                              College of Commerce                   16
Garbage collection Algo.

„   When the garbage collection process an object,
    it makes sure that the object has not already
    been added to the referenced list.
„   An object that was already traversed is skipped.
    It is more efficient to skip an object that is
    already referenced. This also prevents loops. If
    such object were not skipped, a set of objects
    implementing a circular queue would prove
    “infinitely” dangerous.

                  Created By: Asst. Prof. Ashish Shah, J.M.Patel
                             College of Commerce                   17
Garbage collection Algo.

„   Once everyy referenced object
                               j   has been added
    to the graph, the garbage collection algo. Walks
    up the managed heap (from bottom to top).
    Regions in the heap that contained non
    referenced objects are discarded and referenced
    objects are moved down in the heap.
„   An invalid pointer now refers to each object that
    is moved down the heap.
„   The ggarbage
               g collection algorithm
                              g       now traverse
    the active objects and update the pointers
    contained in each reference contained in each
    reference to an object that has been moved.
                  Created By: Asst. Prof. Ashish Shah, J.M.Patel
                             College of Commerce                   18
Garbage collection Algo.

„   The final step is to reset the next object
    pointer.
„   This is the point at which the next object is
    allocated .

                  Created By: Asst. Prof. Ashish Shah, J.M.Patel
                             College of Commerce                   19
Managed Heap Organization..

„   Automatic memoryy managementg        is one of the services
    that the common language runtime provides during
    managed execution.
„   Clr’s
    Clr s GC manages the allocation and release of memory
    for an application.
„   For developers, this means that they don’t have to write
    code to perform memory management tasks when you
    develop managed application.
„   Automatic Memory management can eliminate common
    problems,
        bl     suchh as fforgetting
                              tti tto ffree an object
                                                bj t and d
    causing a memory leak or attempting to access memory
    for an object that has already been freed.

                      Created By: Asst. Prof. Ashish Shah, J.M.Patel
                                 College of Commerce                   20
Managed Heap Organization..

„    The main task in memory managed heap
     organization is done by GC are :
1)   Allocating Memory :
     when new process is initialized, the runtime
     reserves a contiguous region of address
     space for the process. This reserved
     address space is known as managed heap heap.

                 Created By: Asst. Prof. Ashish Shah, J.M.Patel
                            College of Commerce                   21
Managed Heap Organization..

„   The managed g heap    p maintains a p pointer to the
    address where next object in the heap will be
    allocated. Initially this pointer is set to the
    managed heap’s
                heap s base address
                               address.
„   All ref. typed objects are allocated in heap.
„   When next object is created by application
                                         application, the
    GC allocates memory for it in the address space
    immediately following the 1st object.
„   As long as space is available GC continues to
    allocate space for new objects in this manner.

                    Created By: Asst. Prof. Ashish Shah, J.M.Patel
                               College of Commerce                   22
Managed Heap Organization..

„ Allocatingg memory y from the managed g heap  p is
  faster than unmanaged memory allocation.
2) Releasing Memory :
  The GC’s
       GC s optimizing engine determines the best
  time to perform a collection based on the
  allocations being made. When the garbage
  collector
     ll t performs
                f     a collection,
                           ll ti    it releases
                                         l      th
                                                the
  memory for the objects that are no longer being
  used by the application.
  Every application has a set of roots. Each root
  either refers to an object on the managed heap
  or is set to null
               null.
                 Created By: Asst. Prof. Ashish Shah, J.M.Patel
                            College of Commerce                   23
Managed Heap Organization..

„   An application
       application’s s roots include global and static
    object pointers, local variables and referenced
    object parameters on a thread’s stack and cpu’s
    registers.
„   The GC has access to the list of active roots that
    the JIT (Just-in-Time) and the runtime maintain.
    Using this list, it examines an application’s roots
    and in the process it creates a graph that
    contains all the objects that are reachable from
    the roots
        roots.
                   Created By: Asst. Prof. Ashish Shah, J.M.Patel
                              College of Commerce                   24
Managed Heap Organization..

„   Objects that are not in the graph are
    unreachable from the application’s root. The
    garbage
    g     g collector considers unreachable
    objects garbage and will release the memory
    allocated for them.

                 Created By: Asst. Prof. Ashish Shah, J.M.Patel
                            College of Commerce                   25
You can also read