Search code examples
.netmultithreadingmemory-managementheap-memorystack-memory

Threading heap and stack


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.


Solution

  • 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.