0
Can anyone explain me how the memory business works on c ++ ?
Id like to understand better the memory allocation Stuff and how to apply it in code. Share examples, please.
1 Réponse
+ 2
Try to visualize this....
Memory is made up of two things,the 'stack' and the 'heap'..
You can think of the stack as ordered pile of boxes..When you create a function or variable a new box gets added to the stack(no need to worry in this case)...
Visualize the heap as an empty room,when you allocate memory using 'new' , a box is created and put at some random place in the room, with it you'll be able to access and share memory addresses with other variables on the stack(lots of power)..
Just remember to delete all allocated memory on the heap or you'll get strange errors,memory leaks or end up with dangling pointers.....
Theirs so much more that you could do with pointers and dynamic memory allocation,, i think that little intro will help you grasp the concepts really quick..