CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2007
    Posts
    7

    why objects are created on heap?

    Hello
    Hope all will be fine here.

    I want to know why objects are created on heap? what is the benefit of it? cant we manage objects over stack? if not then why?

    Thanks

  2. #2
    Join Date
    Feb 2008
    Posts
    966

    Re: why objects are created on heap?

    Of course you can manage items on the stack. The stack is generally used every time you make a function call and declare local variables used in that function.

    You would use the heap of you had a data structure that was sufficiently large (being as the stack will cause, you guessed it, stack overflow if you exceed the size limits).

    Also, elements on the stack disappear, they are temporary. Elements on the heap are there for the life of the program (static, global variables).

  3. #3
    Join Date
    Mar 2009
    Posts
    1

    Re: why objects are created on heap?

    Objects can be created on heap or stack. It depends on the rule of languages(compilers).

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured