[Autogenerated] So let's test it out and see what we find,
not just in memory but also within process Explorer.
So let's press control of five to launch our first instance.
Here's the first instance and let me go back to visual studio and launch
another instance by pressing control at five again.
So now we have two instances here.
Let's see what process has to say before we test the functionality.
So let's see we're talking about the application that has the name.
Shared, shared demo.
There should be two of those.
Let's find those two here.
There are one beside the other at the lenders were
expecting to find a handle here to a section object that
should have the name we specified.
So let's look for sections here we have a few sections.
Here's our section.
Notice the name.
My shared memory as you might recall or perhaps
you're aware of how these things work.
I mentioned that in the original Windows 11 internal foundations course.
Is that the name is actually session relative by default.
So we have session to that's the name of the number of the session for
this logged in user based on the objects and then the actual name I
provided and the way they create fine mapping works.
Is that the first time you call it?
If there is no such object with this name,
it's being created the next time anyone calls create file
mapping again but provides the same name.
It actually gets a new handle to an existing object.
So this is where sharing comes into place.
In fact,
if you double click that will see that there are two
handles to these section object,
which is what we expect because we have two processes that are
opening handles to the same exact object to verify.
Of course we need to look at the other process as well.
So notice the address here for the section objects.
The only way to know definitively that this in fact points the same object.
So we have here 56 d 10 at the end, going to the other ship.
Looking for a section object, the handle value would be different.
It doesn't have to be the same.
In fact it is different but the address of the object is the same.
If you double click we see exactly the same information
because double clicking shows the properties of the object
rather than the handle itself.
So we have sharing at least of this object.
Which means that what we're trying to do here has a chance of succeeding.
So let's try it out.
Let's write something here by typing something clicking the right button Now,
it should have been written to the to the shared memory which is going to
be in RAM unless it's very problematic in terms of memory consumption and
some of that might be written to the page file.
If I go to the other process and click the red button,
we can see the text right coming back,
which means we are in fact looking at the same memory
sharing memory between these two processes,
you can also allow the VM app and see the addresses that are used.
If we add some diagnostics and some printouts to the application.
If I go ahead and press control at five again to launch yet
another instance that didn't exist at the time we entered that
text and click the red button again.
We see that we get the same value because they're all now
looking at exactly the same memory, exactly the same shared memory.
Going back to process Explorer.
Looking at any one of these handles will find that the object now
has three handles open and open to it by the way,
notice the section information here, it's being committed.
That's what you get normally when using sections
although there are other options.
And then you can see the size here.
The size is exactly one megabyte.
That's the maximum size that we can use for these shared
memory because this is how it was created.
Even though we're mapping just 64 kilobytes at a time
when accessing the shared memory.
The entire memory is one megabyte in size.
And so we can use any one of these instances and all
the others will will see the change.
So Hello world.
Maybe change that to a low memory and its shared, going to click right here.
Going to click read here and read here and we get the same thing If I
close all these instances and then press Control five again to launch one
new one and click the red button will get back.
Nothing.
We get back nothing.
Because once I closed all the instances the section object is gone.
Which means that all the shared memory is gone as well.
And because we use the page file as the back backup for this memory,
that memory is recycled and it's gone.
If I would have used an actual file then the memory would have
survived and we'll see that in the next clip.