I read about Shared memory from here. As per the document, two different program generate two different virtual addresses and those virtual addresses map to same physical page in RAM.
So when program1 accesses data of shared memory then it will be loaded from main memory to cache and next time program2/process2 will get the data from cache so lower access time for the same data for program2/process2.
I have successfully written a program in C language for IPC using shared memory to communicate between two programs and to modify a variable in one program and read from other program.
Now, my questions are as follows:
Can "Shared memory" be automatically created between two independent programs? Means is it possible that two independent programs automatically create share memory by themselves or by OS, without manually/programmatically creating shared memory like for IPC (shmget/shmat)?
When two different virtual addresses map to same physical memory using shared memory, is it always true that those two programs' common data is present OR it can be possible different data may be present at that shared memory location (which will cause more cache miss)?
Can we decide or create share memory between two independent programs without knowledge of other programs?
Suppose, in program-1 I have declared an Array-A of size 1 MB and in program-2 I have declared Array-B size 16KB. Now while performing summation operation in both programs, will it still benefitted due to shared memory?
Means When an element is loaded in cache for summation, then other program will use that cached value.
OR
There is no possibilities of shared memory as we are using two different Array and there elements are not useful to other program/process.
I am using GCC under Linux.