I was wondering when to use heap based allocations vs stack based ones. Even though ive been programing for about a year or two ive still never used anything thats heap based. I dont know if i just havent had any legit uses for it or im just too n00b
The stack has much less available memory than the heap. This is mostly a problem if you allocate huge (multidimensional) arrays, or have deep or infinite recursive functions.
Another thing is that allocations on the stack must have a fixed size known at compile time and it is destroyed when it goes out of scope. With heap allocated objects there is much more freedom to decide when an object should be destroyed. This makes the stack unstable for collection of things where you can add and remove elements. std::vector, std::string, std::list, etc. all use heap allocations internally.