What's the difference between a stack and a heap? The differences between the stack and the heap can be confusing for many people. So, we thought we would have a list of questions and answers about stacks and heaps that we thought would be very helpful. Where are the stack and heap stored? They are both stored in the computer's RAM (Random Access Memory). For a refresher on RAM and virtual memory, read this article: How Virtual Memory Works How do threads interact with the stack and the heap? How do the stack and heap work in multithreading? In a multi-threaded application, each thread will have its own stack. But, all the different threads will share the heap. Because the different threads share the heap in a multi-threaded application, this also means that there has to be some coordination between the threads so that they don't try to access and manipulate the same piece(s) of memory in the heap at the same time. Can an object be stored on the stack instead of the heap? Yes,
Read full article from Stack versus Heap
No comments:
Post a Comment