Reputation: 601
In the book Expert C Programming
P101, there is a paragraph:
For example, if you have eight XViewTM applications running, only one copy of the XView library text segment has to be mapped into memory. The first process's mmap [1] call will result in the kernel mapping the shared object into memory. The next seven process mmaps will cause the kernel to share the existing mapping in each process. Each of the eight processes will share one copy of the XView library in memory. If the library were statically linked, there would be eight individual copies consuming more physical memory and causing more paging.
Since mmap only return a pointer of the memory, I wonder how can I use the variables or call a method defined in the library?
Upvotes: 0
Views: 1325
Reputation: 249223
This is describing a mechanism that is used automatically by the system. You don't need to do anything other than link your program against shared libraries to take advantage of this sharing. You certainly do not need to call mmap()
yourself, or figure out how to call functions in some special way.
Upvotes: 1