16
General / Re: When should I be using pointers?
« on: August 22, 2017, 09:36:05 am »
Firstly, a bit of theory:
https://stackoverflow.com/a/79936
Now, If the stack model is convenient for you (small size, short lifespan, etc..), use it, there's no reason not to (however,make sure you're not creating global variables just so you can use stack model. Always avoid globals). Only use heap if stack memory management is insufficient.
On top of that, when you finally use pointers, use smart pointers instead of the raw ones, as smarts are safer.
https://stackoverflow.com/a/79936
Now, If the stack model is convenient for you (small size, short lifespan, etc..), use it, there's no reason not to (however,make sure you're not creating global variables just so you can use stack model. Always avoid globals). Only use heap if stack memory management is insufficient.
On top of that, when you finally use pointers, use smart pointers instead of the raw ones, as smarts are safer.