How memory is allocated in case of spawning a new thread, i.e how memory heap, memory stack, and threads are related? I know this is fundamental (.net framework concept) but somehow I am not much aware of this concept.
It's really hard to answer this question because of the way .Net threads are implemented. There is not necessarily a 1-1 implementation between managed and corresponding native threads. The CLR is free to use multiple native threads to implement a single managed thread. So allocating a new managed thread does not necessarily cause a native thread to be spawned. It can simple assume an existing one.
Can you tell us why this is of concern for you? Perhaps that will lead us to a better answer.
The stack belongs to the thread context. The heap belongs to the process, it is hence shared between the threads.
It is fundamental much deeper than .net. Threads are OS native objects. What is called Managed Thread is just wrapper around native thread.
So back to your question. Memory heap is shared accross threads of same process because they are located in single virtual memory space. Stacks are individual.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With