I am trying to understand the basic concept of shared memory. I am trying to create a shared library that has one function and one STATIC array variable. I want to access a variable of a static array through a function of this shared library.
Here is my shared library
//foo.c #include <stdio.h> static int DATA[1024]={1 ,2 ,3 ,...., 1024}; inline void foo(void) { int j, k=0; for(j=0;j<1024;j++) { k=DATA[j]; } k+=0; }
I created a shared library object (libfoo.so) following the instructions from the shared library
Now my questions
1> If I access foo () from two different programs (program1 and program2), will there be a separate copy of the foo () function for program1 and program2?
2> will a separate copy of the DATA static array appear for program1 and program2?
3> Will they be loaded into the same physical memory cell? If a static DATA array is loaded separately, is there a way to force it to load into the same memory location?
4> Is there a way to find where the DATA static array is stored for program1 and program2?
I am using gcc under linux. Any help would be greatly appreciated. Thanks in advance.
c linux shared-memory shared-libraries
bholanath
source share