stack vs heap

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RS24
    New Member
    • Oct 2006
    • 9

    stack vs heap

    hi!
    Among stack n heap, which is faster ? (In C/C++)
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Rather depends on where and how they are implemented.

    Anyway which is faster for what?

    Comment

    • RS24
      New Member
      • Oct 2006
      • 9

      #3
      Originally posted by Banfa
      Rather depends on where and how they are implemented.

      Anyway which is faster for what?
      Actually, I don't know! I am a computer engineer (fresher) , looking for job. They had this question in the test paper for a job. It was exactly " Which is faster - heap or stack? Explain with example" . And I didn't know what was it about!
      Could u tell something?
      I'll b really grateful !
      Thanks

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        I wouldn't really expect 1 to be faster than the other they should both be in RAM for the current platform so they should both go about the same speed.

        Generally you only use the stack for auto variables and these are allocated for you where as you use the heap when you malloc or new variables so allocating memory on the stack is marginally faster as it is done as part of the function call when it creates a stack frame where as allocating memory from the heap takes a function call, but that is about it.

        Comment

        Working...