Jump to content
  • Advertisement
Sign in to follow this  
Fixxer

Using the heap

This topic is 4727 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I just recently read about the heap in my new book, and im wondering how important is it to have a good background in this? Is the stack really that small? When writing normal applications or games, will I need to use the heap alot, or only for extreme cases?

Share this post


Link to post
Share on other sites
Advertisement
You will definatly need to use the heap when you program any significant game or application, so you should definatly learn how to use it.

It is not very difficult anyway.

I think the stack is only a couple of meg in size so that doesn't give you much memory to play with

Share this post


Link to post
Share on other sites
Generally speaking, use the stack where you can; use the heap where you need to.

As you progress as a programmer you will develop an intuition about what problems are better solved on the heap. Generally the heap is used where a dynamic allocation is required (i.e. the amount of space needed will vary at, and/or not be known until, runtime), or to allow for data to persist between function calls. However, be aware that for the dynamic allocations, it is often better to stack-allocate a standard library object which will in turn manage the heap allocation for you (for example, std::string or std::vector).

Share this post


Link to post
Share on other sites
Quote:
Original post by Fixxer
I just recently read about the heap in my new book, and im wondering how important is it to have a good background in this? Is the stack really that small? When writing normal applications or games, will I need to use the heap alot, or only for extreme cases?

What language are you learning?
In c# and java value types are created on the stack and reference types are created on the heap that's all you have to know.
If you are using the keyword "new" you are most likely using the heap.
If you are using c# or java you really don't have to worry about it too much since it's all taken care of automatically for you. Only time you would need to concern yourself is if you are concered about performance.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!