Stack and heap
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Stack and heap

  1. #1
    Join Date
    Jul 2003
    Location
    Singapore
    Posts
    1,822

    Question Stack and heap

    hi...i've always wanted to know what the difference between stack and heap??
    when we create a class in C#, say for eg. a class TinCan
    TinCan t1;
    i came to know that it is created on stack!
    Q : Wat is stack? why is it created on statck and not on heap?

    then lets say i initiate my reference by creating an object
    t1 = new TinCan;
    i came to know that this allocates space in memory on the Heap!
    Q :What is a heap? why is it now created on heap instead of stack?

    Q : Why does C# create the reference on stack and objects on heap?

    Q : Whats the difference between stack and heap?

    tks a lot for any help!
    R. Thomas
    "Be anxious for nothing, but in everything by prayer and supplication, with thanksgiving, let your requests be made know to God; and the peace of God, which surpasses all understanding, will guard your hearts and minds through Christ Jesus."Philippians 4:6-7
    "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18

  2. #2
    Join Date
    Mar 2002
    Location
    NY, USA
    Posts
    12,097
    Simply stated stack is memory that is only allocated for the duration of the current scope. Heap is allocated/released with new and delete.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009
    In theory, there is no difference between theory and paractice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  3. #3
    Join Date
    Jul 2003
    Location
    Singapore
    Posts
    1,822
    but then which is long term??which is short term??
    what kinda variables go to stack what kinda go to heap?
    tks for any help
    R. Thomas
    "Be anxious for nothing, but in everything by prayer and supplication, with thanksgiving, let your requests be made know to God; and the peace of God, which surpasses all understanding, will guard your hearts and minds through Christ Jesus."Philippians 4:6-7
    "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center