Using the heap
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?
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
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
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).
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).
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement