Question

Suppose I have .Net application App.exe which creates three domains: DomainA, DomainB and DomainC.

Can we say that CLR assigns to App.exe process some amount of physical memory, and then this memory is divided in some proportion between our three domains?

Or for each new domain, a new separate portion of memory is given independently of the memory allocated for App.exe and other domains?

In simple words: can I imagine logical memory allocation as a (sequential) tape with songs (where songs are AppDomans), or as a kind of FAT32, where files located randomly and we just know their locations on the disk?

Was it helpful?

Solution

Can we say that CLR assigns to App.exe process some amount of physical memory

You cannot say that, a process on Windows only allocates virtual memory. The mapping of virtual memory to physical memory (RAM) is strictly an operating system duty. RAM needs to be shared by all processes running on the machine and is done dynamically. The sum of the virtual memory allocations of all processes normally greatly exceeds the amount of RAM. When a process accesses virtual memory, a page fault gets the virtual memory page mapped to RAM. If necessary, data in RAM is discarded or stored in the paging file to make room.

AppDomains share a single set of GC heaps (generations 0 through 2 and the Large Object Heap) and their allocations are intermingled. They are kept apart by their roots, every AppDomain has its own heap for static variables, its own GCHandles and its own set of thread stack frames with local variables.

OTHER TIPS

The entire memory managed by the CLR is process-global. AppDomains do not play a role here. It does not matter how many AppDomains you have, allocation always comes from the same global heap(s). The heap expands and shrinks as demanded. There is no static allocation of memory.

I believe the JVM does use a static allocation for heap size for reasons unknown to me. The CLR is different.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top