The memory stack of a program is limited in size by default. So if you throw too much data in there, like function parameters you call, then you can run out of space.
This is very common if you get function calls in a loop or recursion when you don’t exit properly and the stack fills up its memory until it default (or configured) stack size is exceeded.
Things are pushed into the stack, like function calls and parameters, and popped off the stack, like function return values. Pushing too much stuff on runs out of space.
If you need bigger things in more space you allocate it to the heap.
For example. 16 bit integer (2 bytes) might be on the stack, but if you have a long string, which is 1gb in size, that would be allocated on the heap, and that heap’s memory address would be on the stack.
This is relevant to when you pass arguments to functions by value (on the stack) such as the number “7” or by reference (to the heap) such as text or a binary image and pass only the memory address.
Latest Answers