5

Recent versions of .NET do allow to create more then one CLR within one process(Is the garbage collector in .net system-wide or application-wide?).

So basically we can have more then 1 heap within one process. So how do domains affected by this change? Do domains still share heap within one process?

PS: Where is thread context saved, while context switch happens in multiprocessor OS?

trincot
  • 317,000
  • 35
  • 244
  • 286
Johnny_D
  • 4,592
  • 3
  • 33
  • 63
  • I'd guess thread context is saved by the OS task scheduler and CLR only has a thin wrapper around that. You can read more [here](http://www.codeproject.com/Articles/662735/Internals-of-Windows-Thread) (search for "thread context") and in the Windows Internals book, I think it's part 1. – oleksii Nov 26 '14 at 11:06
  • 1
    Domains share the same heap, yes. But not side-by-side versions of the CLR, they are completely independent from each other and create their own domains and heap. If you *actually* use the feature, only applicable to native programs that host the CLR themselves or use COM to interop with a .NET [ComVisible] component then you never care about this. – Hans Passant Nov 26 '14 at 14:00
  • ...and the additional thread-related data that the CLR need are saved in an object (a unmanaged relative of Thread), whose pointer is saved in the one of the TLS slots. The article oleksii links too explains how the TEB and TLS work. – Lorenzo Dematté Dec 17 '14 at 09:28
  • Oh, and actually, since a host can change how memory allocation is done "domains share heap within a process" is an implementation detail which can be changed. It should not matter, anyway, since you cannot "legally" access in a *direct* way data in another domain (and even if data is allocated from different heaps it is still inside the same process space) – Lorenzo Dematté Dec 17 '14 at 09:31

0 Answers0