0
What's the deal with pointers to the heap?
If I get it right, I guess the benefit of working with pointers to "new" things that are deleted when no longer useful is minimizing the size of the program when idle and only using memory for variables and containers of variables when the program is running. Is that right? Also, are heaps and stacks automatically created for all programs? A tutorial suggested so, but I've also seen stuff that indicates otherwise.
2 ответов
+ 1
The "stack" in memory represents all predifined variables in your c++ application by the complier. Yet, during runtime, your memory uses the "heap" to make room for more space for variables of any size. Pointers are used to store the address of allocated memory within the heap during runtime.
For example, if you were to create a linked list, you cannot declare 4 slots for nodes. So along the way, when you tell the program to add a node to the linked list, you use pointers to grab "random access memory" of some sort and store information.
I hope this clarifies your questions on pointers and memory usage within C++ programs.
0
Yeah, pretty much
thanks!