+ 1
Confused about Dynamic Memory
Are there other resources that can help me understand dynamic memory and pointers?
8 Respostas
+ 6
I hope I can explain it , so it doesn't get too
confusing. Dynamic memory allocation is
where you control the lifetime of your
variables . Local variables are stored on the
stack. Think of variables in a stack as a stack of plates or a pile of plates one on top of
the other.
Variables that are pushed on the stack
first are poped off the stack last , and
variables pushed on the stack last are
poped off the stack first (LIFO).
Local variables go out of scope when
a function is finished .
But in Dynamic memory , variables go on the heap or free store , a area of memory not
used by the program . The advantage of
allocating memory from the heap is that
the memory you reserve remains available
until you release it.
You allocate memory with the new operator
in C++, C# and Java, and in C it's malloc ().
Also in programs such as C and C++ , you
are in charge of releasing memory . In
C#, Java , and other programming
languages, they take care of releasing
memory for you.
+ 6
Look at my answer here for a topical analogy related to pointers and values (memory concepts are only peripheral though).
https://www.sololearn.com/Discuss/925671/?ref=app
+ 5
I am glad you thought my answer helped
you understand about Dynamic Memory.
+ 3
Dynamic memory is for allocating variables to the Heap. That is done when variables are of unknown size and may get really huge. Pointers point to the Heap where the variable's address is. They take up very little space.
+ 2
Thanks Rick that was very helpful
+ 1
Which is the doubt that you dont understand? Maybe i can help you or other person.
+ 1
I think I don't understand how it is used. Why do it? The reasoning? Example might help. @lago
0
Try to read this pages, and if you continues with doubt, ask and we try to give you a good answer.