467,879 Members | 1,301 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,879 developers. It's quick & easy.

multiple instances of executable using static library instead shared library

100+
I created an executable using static library instead shared lib, I am running multipe instances of this executable, does it takes more memory with static library compare to shared library?.

Does shared library had any advantage than static library in multiple instances?. thanks in advance
Dec 14 '09 #1
  • viewed: 3754
Share:
4 Replies
Banfa
Expert Mod 8TB
With a static library all the code is in the program. With a shared library the OS loads the library code separately, no matter how many programs are using the library only 1 instance of the library code is loaded.

So yes running several instances of a program linked with a static library as opposed to a shared library will use more memory. The real question though is it significant. If you static library is only a few kbytes in size then it probably makes little difference, if your program creates large amounts of actual data, which is unaffected by the code being in a static or shared library then it is likely that the memory used for data far out-weighs the memory used for code and again it may be insignificant.
Dec 14 '09 #2
Expert 2GB
It also depends on what operating system your program executes under. Some operating systems deal with multiple instances of the same executable by loading only a single copy of the text section and per-instance copies of the bss and data sections.

Under such an operating system, multiple instances of the same program show no benefit of shared library over static library. Instead, you don't see the advantage until you have two different programs that both include the same portions of a shared library.
Dec 14 '09 #3
100+
I created an executable by linking Nine static libraries, I am running 32 instances of this execuatble in Linux, how I will know whether it is using single copy of text sectioon or multiple of copies, Is there any command in Linux (RH)?. I created Nice shared libs also, but when I created executable using shared libs, it is not working, I have to debug whe my shared libs exe file not working, where as static libs linked exe file works.
Dec 15 '09 #4
100+
I created 9 static libs (x1.a x2.a x3.a....x9.a) and 9 shared libs (y1.so, y2.so,....y9.so) when linking with static libs everything looks ok, but when linking with shared libs, it is not working), for final linking I am using -static when linking with static libs, where as I am not using any flag when linking with shared libs, do I have to use any other flag with shared libs?.

1) this command to create final exe file using static libs

gcc -static -Wall -g -O2 xyz1.o xyz2.o xyz3.o -L/opt/lib -lx1 -lx2 -lx3 ... -lx9 -ldl -lpthread -lm -lstdc++ -o final-exe-file

2) this command to create final exe file using shared libs

gcc -Wall -g -O2 xyz1.o xyz2.o xyz3.o -L/opt/lib -ly1 -ly2 -ly3.... -ly9 -ldl -lpthread -lm -lstdc++ -o final-exe-file
Dec 15 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by =?Utf-8?B?VG9kZA==?= | last post: by
4 posts views Thread by Nethali | last post: by
reply views Thread by jack112 | last post: by
reply views Thread by MrMoon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.