Using the heap

Started by
4 comments, last by daviangel 18 years, 10 months ago
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?
Advertisement
Lean as much as you can man! The more the better...
Take back the internet with the most awsome browser around, FireFox
i am, ive got over 1500 pages of C++ and direct x reading for the summer =)
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
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).
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.
[size="2"]Don't talk about writing games, don't write design docs, don't spend your time on web boards. Sit in your house write 20 games when you complete them you will either want to do it the rest of your life or not * Andre Lamothe

This topic is closed to new replies.

Advertisement