Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do shared libraries help save memory?

I want to clear up a confusion I have regarding shared libraries. When I search online, I find in explanations to static linking that since the library is included in the executable itself, it leads to a larger executable, increasing the memory footprint of the program.

While in case of dynamic library/shared library, the library is linked at runtime. But in dynamic linking (correct me if I'm wrong), if the library is loaded into the process at runtime to be linked, does it then lead to any memory saving in any way ?

like image 454
Jake Avatar asked Jul 28 '26 13:07

Jake


1 Answers

The library is loaded once into memory by the OS, and is linked to the running process by mapping its memory location into the processes virtual address space. From the processes point of view, each has its own copy of the library, but there is really only one copy in memory.

like image 70
mindcruzer Avatar answered Jul 30 '26 02:07

mindcruzer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!