[Autogenerated] sharing code pages is fairly easy between
processes because code is read only by definition and that
happens not just for DLS, but also for processes that are running the same image.
So if I run multiple instances of Notepad the Notepad executable code
is going to be made to the same location in physical memory and in
virtual memory in order to conserve physical memory because it is the
same code for DLS as we've seen,
They must be loaded into the same virtual address.
And this is mostly happening automatically these days
because of a feature called address space,
lower organization or SLR and I'll discuss a seller in the last module in
this course and we'll see why that guarantee is almost 100% that that kind
of code sharing would happen for dealers as well.
What about data?
Data is normally read write,
which usually means that every process should get its own copy.
However, even in this case,
the memory manager tries to share the data up front
unless some process rights to the data.
And this is done by providing a special protection over
those pages that are considered data,
something called copy on write and copy and right means exactly what
it sounds like when you make a write operation,
a copy will be created.
So if one process changes the data, at least one of the pages in the data,
it will get that page as a private copy,
removing the copy on write protection.
So it has its own data now.
So even with this scheme, the mail manager is is able to save physical memory.
It is also possible by the way to share data without copying.
Right?
So in that case, if one process changes the data,
other processes that are looking at the same data will see the change.
And this is in fact sometimes useful and kind of a poor man's way
of doing sharing of memory between processes.
We'll see a more elaborate scheme in a later module in this course.
So here's what that looks like.
Let's have two processes here that are using the same DLL
and so that deal might have global data.
So this global data in this example consists of three pages and so they're
initially mapped to exactly the same location in physical memory with the
copy and write protection over the virtual pages.
Let's assume now that process be decide To write into page # two.
So when that happens the copy and write flag calls an exception
to be to be raised by the processor and the memory manager will
create a copy of that data and re map that page to the new data
page in physical memory,
essentially giving process be a private copy of the data.
This allows the member manager to be as conservative as possible,
but still allow every process to see its own data as it's the way
it should be for most cases for read write data