Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Process memory v.s. AppDomain memory allocation

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?

like image 996
user2341923 Avatar asked Feb 16 '23 10:02

user2341923


2 Answers

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.

like image 186
Hans Passant Avatar answered Mar 17 '23 03:03

Hans Passant


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.

like image 32
usr Avatar answered Mar 17 '23 04:03

usr