Results 1 to 3 of 3

Thread: C# Me Heap And Stack kia hotay?

  1. #1
    saima5 is offline Senior Member+
    Last Online
    28th December 2013 @ 09:24 AM
    Join Date
    13 Nov 2012
    Gender
    Female
    Posts
    33
    Threads
    7
    Credits
    0
    Thanked: 1

    Default C# Me Heap And Stack kia hotay?

    Plz SomeOne tell me
    k
    C # HEAP AND STACK KIA HOTA HAII???
    please koi zrur batai
    with example
    aur urdu me batai...

  2. #2
    saima5 is offline Senior Member+
    Last Online
    28th December 2013 @ 09:24 AM
    Join Date
    13 Nov 2012
    Gender
    Female
    Posts
    33
    Threads
    7
    Credits
    0
    Thanked: 1

    Default


  3. #3
    imranjhang's Avatar
    imranjhang is offline Senior Member+
    Last Online
    11th May 2021 @ 02:36 PM
    Join Date
    17 Dec 2009
    Age
    38
    Posts
    94
    Threads
    1
    Credits
    1,390
    Thanked
    13

    Default

    Computers use memory to hold programs being executed and the data that these programs
    use . To understand the differences between value and reference types, it is helpful to understand how data is organized in memory .
    Operating systems and language runtimes such as that used by C# frequently divide the
    memory used for holding data in two separate chunks, each of which is managed in a
    distinct manner . These two chunks of memory are traditionally called the stack and the heap .
    The stack and the heap serve very different purposes:
    n When you call a method, the memory required for its parameters and its local variables
    is always acquired from the stack . When the method finishes (because it either returns
    or throws an exception), the memory acquired for the parameters and local variables is
    automatically released back to the stack and is available for reuse when another meth-
    od is called .
    n When you create an object (an instance of a class) by using the new keyword, the mem-
    ory required to build the object is always acquired from the heap . You have seen that
    the same object can be referenced from several places by using reference variables .
    When the last reference to an object disappears, the memory used by the object be-
    comes available for reuse (although it might not be reclaimed immediately) . Chapter 14
    includes a more detailed discussion of how heap memory is reclaimed .
    Note All value types are created on the stack . All reference types (objects) are created on the
    heap (although the reference itself is on the stack) . Nullable types are actually reference types,
    and they are created on the heap .
    The names stack and heap come from the way in which the runtime manages the memory:
    n Stack memory is organized like a stack of boxes piled on top of one another . When a
    method is called, each parameter is put in a box that is placed on top of the stack . Each
    local variable is likewise assigned a box, and these are placed on top of the boxes al-
    ready on the stack . When a method finishes, all its boxes are removed from the stack .
    n Heap memory is like a large pile of boxes strewn around a room rather than stacked
    neatly on top of each other . Each box has a label indicating whether it is in use . When a
    new object is created, the runtime searches for an empty box and allocates it to the ob-
    ject . The reference to the object is stored in a local variable on the stack . The runtime
    keeps track of the number of references to each box . (Remember that two variables
    can refer to the same object .) When the last reference disappears, the runtime marks
    the box as not in use, and at some point in the future it will empty the box and make it
    available for reuse .

    The above text is copied from ebook "Visual C# 2010 Step by Step - John Sharp"

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •