Will multiple instances of an executable (built with static libraries) share anything on RAM
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 th开发者_JAVA百科e 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.
精彩评论