1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Difference between stack mamory and heap memory?

Discussion in 'C' started by salonibhutani86, Sep 12, 2010.

  1. salonibhutani86

    salonibhutani86 New Member

    Joined:
    Sep 12, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    what is the difference between stack mamory and heap memory?
     
  2. LordN3mrod

    LordN3mrod New Member

    Joined:
    Sep 4, 2010
    Messages:
    22
    Likes Received:
    11
    Trophy Points:
    0
    Occupation:
    Software Developer
    Location:
    Yerevan, Armenia
    Re: question

    Well, first of all, I think you should have googled it, and THEN, if you had any questions posted them here... but hey! :)

    So, an object can have either automatic(stack) or dynamic(heap, or, more formally, free store) storage duration. There is also a third type of storage, that is, static storage, but I won't talk about it at the moment.

    Any object created with 'new' is created on the heap, that means, its lifetime won't end until the program ends, or you explicitly call delete. On the other hand, any local object that was not created with 'new' is created on the stack, and its lifetime ends as soon as the control goes out of the block the variable was declared in.

    Again, better google it
     
    shabbir likes this.
  3. singhsan02

    singhsan02 New Member

    Joined:
    Sep 22, 2010
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    DiD you meant Heap and Free Store are same? I guess its not the same.
     
  4. LordN3mrod

    LordN3mrod New Member

    Joined:
    Sep 4, 2010
    Messages:
    22
    Likes Received:
    11
    Trophy Points:
    0
    Occupation:
    Software Developer
    Location:
    Yerevan, Armenia
    The C++ standard does not say anything about a 'stack' or a 'heap'. It operates with terms 'automatic' and 'dynamic'. The standard does not mandate how new be implemented, it only mandates the behaviour. There is a logical reason why automatic memory should be called a stack - that is because nested scopes are a stack in a sense. On the other hand I see no connection between a heap the data structure and a heap the memory. That's why I personally prefer the term free store. And yes, the free store and the heap is exactly the same thing in this context. Do you disagree?
     

Share This Page