Assume a executable foo.exe is built based on static libraries and 6 instances of this foo.exe are running at the same time on the a machine. Since all the code is same (read only part) except for the read write part on the RAM, will there be any sharing amongst these 6 instances in the RAM to improve performance ?
I do know that if the above foo.exe uses shared libraries instead ,even though there are 6 instances running only 1 instance of these shared libraries will be in the RAM.
It depends on the OS.
For Linux and Solaris, all the instances will definitely share the memory pages that hold the code (or text as it is properly called).
They may also share data pages that originate from the executable (i.e. for global and static data). What happens is those pages are shared with a technique called copy-on-write or COW. As long an instance does not modify the data pages, they will be shared. But once a instance modifies a data page it will get it's own copy.
I'm guessing that modern versions of Windows does the same thing, but I don't know for sure.
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