Libs/dll on the device?

Login to reply to this topic.
Wed, 2007-04-04 07:31
Joined: 2004-06-22
Forum posts: 148
Hi,

Can someone please tell me what r the advantages/disadvantages of using a dll over a static lib and vice versa? And when to use a dll and when to use a lib..and what r the implications of using each of them on the device..are there any performance/speed overheads on either of them..?

Cheers
mayank

Wed, 2007-04-04 13:51
Joined: 2006-10-07
Forum posts: 131
Re: Libs/dll on the device?
Static library becomes a part of the executable. That means, every application that links it will have a copy. With DLL (or shared library) you only link to export library which tells your application what functions are located at which addresses in a shared library. All applications will use only one copy of a DLL (saving memory).

If you have applications which share a good chunk of code, it makes sense to use a DLL.


Not sure about DLL overhead, there should not be any apart from loading the library when it is requested the first time. Someone, correct me if I'm wrong.
Wed, 2007-04-04 15:24
Joined: 2004-06-22
Forum posts: 148
Re: Libs/dll on the device?
but what if i have the structure where for abstraction sake i make my own dlls/libs which r just going to be used by my exe..i mean its like i have one exe..and 3-4 libs/dlls which only the exe is going to use..then which to make..libs or dlls?

cheers
mayank
Wed, 2007-04-04 16:38
Forum Nokia Champion
Joined: 2003-06-10
Forum posts: 695
Re: Libs/dll on the device?
DLLs use RAM only when loaded. If you use a static library, then the memory is always consumed when you load your app. In a resource costrained device like a mobile phone, it is best (for the phone user and other apps he/she might wish to run at the same time) to try to use as little memory and as few processor cycles as you possibly can.
Tue, 2007-04-10 15:35
Joined: 2005-06-09
Forum posts: 174
Re: Libs/dll on the device?
But on the other hand, DLL:s used by your app are loaded when the app is started, so it's not like you're saving memory by using statically linked DLL:s instead of statically linked libraries.

Thu, 2007-04-12 10:18
Forum Nokia Champion
Joined: 2003-10-01
Forum posts: 721
Re: Libs/dll on the device?
Quote from: puterman
But on the other hand, DLL:s used by your app are loaded when the app is started, so it's not like you're saving memory by using statically linked DLL:s instead of statically linked libraries.

But the second app will not need to load the DLL again as it's already been loaded into RAM. As opposed to static LIBs.

But to also answer Mayankkedia's question: you don't need to make a separate DLL or LIB just for abstraction's sake. You can write mixins, isolate functionality in separate src/inc directories so that, when needed, you can easily put them in another file.

Tote

Gabor Torok
Software architect, Agil Eight (http://www.agileight.com/)
Blog: http://mobile-thoughts.blogspot.com/

Thu, 2007-04-12 10:58
Joined: 2006-10-07
Forum posts: 131
Re: Libs/dll on the device?
I split projects for faster build times. Sometime I need to do a clean rebuild, and with big projects it is very irritating.
Thu, 2007-04-12 11:10
Forum Nokia Champion
Joined: 2003-10-01
Forum posts: 721
Re: Libs/dll on the device?
That's right.

Gabor Torok
Software architect, Agil Eight (http://www.agileight.com/)
Blog: http://mobile-thoughts.blogspot.com/

Thu, 2007-04-12 11:17
Joined: 2004-11-29
Forum posts: 1134
Re: Libs/dll on the device?
Wouldn't you need to rebuild all dlls of your project to do a real "clean rebuild" anyway?

If you need to rebuild source file, it is because it has binary dependencies on some other part.
You don't solve this problem by splitting it in separate dlls.
You solve it by getting rid of the binary dependency
And you can do that with just proper moduling in different source files.

It might be easier to keep track of though if you keep it in separate dlls, because it will kick you in the nuts if you mess it up, but on the other hand it might be trickier to resolve dependency problems when they arrive, and they might be there without you realizing it, because the build environment doesnt warn you properly..

I dont see the point to split your program into several binaries just for abstractions sake.
Dlls is for shared code, all other code could just as well be statically linked.

Actually, you often gain a bit memory from useing a static linked lib, if you have a big lib with lots of functions, of wich you only use a few.


And, what do you gain by abstracting it in a dll as opposed to a static lib?

just my 2 cents Smiley
Thu, 2007-04-12 11:25
Forum Nokia Champion
Joined: 2003-10-01
Forum posts: 721
Re: Libs/dll on the device?
Quote from: alh
I dont see the point to split your program into several binaries just for abstractions sake.
Dlls is for shared code, all other code could just as well be statically linked.

Okay, just for abstraction's sake there might not be big benefits unless it's a big project and re-building it really takes time. In the latter case, you can split up your component into several DLLs (or LIBs, depending on how many clients you anticipate for the DLLs/LIBs) and a main executable. If you insist on a fixed API (and preferably binary compatibility) in your DLLs, then building time might be only a small fraction of the original period it took to build the whole system.

Tote

Gabor Torok
Software architect, Agil Eight (http://www.agileight.com/)
Blog: http://mobile-thoughts.blogspot.com/

Thu, 2007-04-12 12:04
Joined: 2004-11-29
Forum posts: 1134
Re: Libs/dll on the device?
Quote from: tote
Quote from: alh
I dont see the point to split your program into several binaries just for abstractions sake.
Dlls is for shared code, all other code could just as well be statically linked.

Okay, just for abstraction's sake there might not be big benefits unless it's a big project and re-building it really takes time. In the latter case, you can split up your component into several DLLs (or LIBs, depending on how many clients you anticipate for the DLLs/LIBs) and a main executable. If you insist on a fixed API (and preferably binary compatibility) in your DLLs, then building time might be only a small fraction of the original period it took to build the whole system.

Tote

Yes. As I said. Shared code in dlls.
Everything else statically linked.

Clarification:
If you have a big pile of code that doesn't change much (compared to the rest of your system), it could be a good idea to put it in a (statically linked) lib.

But there really isn't much point in a dll unless you share the code.

Or want to be able to upgrade the dll independently from the rest of the system.

If you don't, putting it in a dll will just give you more work for no gain.

Also, it will take more memory to have it in a dll then in a static lib if it is only used by one binary.
Thu, 2007-04-12 12:29
Forum Nokia Champion
Joined: 2003-10-01
Forum posts: 721
Re: Libs/dll on the device?
Good answer. Smiley Although I wouldn't be worried about the size overhead resulted in from using a DLL with a single client, all the rest applies.

Tote

Gabor Torok
Software architect, Agil Eight (http://www.agileight.com/)
Blog: http://mobile-thoughts.blogspot.com/

Thu, 2007-04-12 14:08
Joined: 2006-10-07
Forum posts: 131
Re: Libs/dll on the device?
Quote from: alh
Wouldn't you need to rebuild all dlls of your project to do a real "clean rebuild" anyway?
Nope. You need only to rebuild one DLL and a sis file for main project. Unless you use project references that forces clean+rebuild of child projects.
Thu, 2007-04-12 14:57
Joined: 2004-11-29
Forum posts: 1134
Re: Libs/dll on the device?
Quote from: sysctl
Quote from: alh
Wouldn't you need to rebuild all dlls of your project to do a real "clean rebuild" anyway?
Nope. You need only to rebuild one DLL and a sis file for main project. Unless you use project references that forces clean+rebuild of child projects.

Well, if you don't have any dependencies between the different .o files, you don't have to rebuild them either.
Just rebuild the .o-files with the dependencies.
This make takes care of for you, as long as your dependencies are set up right.

Now its true the symbian build environment might force you to rebuild things you shouldn't need to sometimes, usually because of resources...

But its still not a reason to put it in a DLL, freeze the API, and allocate a UID to it.
You get that same modularity without the work overhead of messing with freeze files (not that its that much problem, but frustrating when it messes with you) by putting in it a static lib.

Also, the linker can to a better job if its in a lib instead...
I think you should try put your code in a static lib and link it in, and compare the binary size of the result to the binary size of the two dlls...  I think you might be supprised Smiley (I know I was)

This all still if the code is not shared...  If it is, then ofcourse, dlls are the way to go.
Fri, 2007-04-13 16:44
Joined: 2004-11-29
Forum posts: 1134
Re: Libs/dll on the device?
Just wanted to add another note why useing a DLL might give you more work then needed:

You also need to maintain binary compatibility (that is, the size of the object too), not just the API entry function order (freeze .def file), if you want to avoid having to rebuild "everything"

This can be quite a hassle in early development.

It means you can not add any new members variables to the exported class, and nor can you add any virtual functions too it, or you will open a can of User:42. (until you makes sure you clean up .lib files (which the build system have a a habit of leaving, even if you do a reallyclean), and relink the user of the DLL)

This is not a problem with static libs.
Fri, 2007-04-13 21:31
Forum Nokia Champion
Joined: 2003-10-01
Forum posts: 721
Re: Libs/dll on the device?
Alh,

It's mostly true. However, especially in early development there are methods to minimize the hassle. Typically, you publish the API of your DLL in a stub component that you're going to develop further while others are writing their own code relying on your published DLL. Of course, re-building will most probably be necessary but at least you can try to keep the number of it at minimum.

Also, you're recommended to write your API using the Bridge design pattern, which gives you the freedom of modifying the API (data members, non-published helper methods in your class, etc.) freely.

But, again, in general you're right. DLLs, especially when used by others, binds you to keep every kind of compatibility you can.

Tote

Gabor Torok
Software architect, Agil Eight (http://www.agileight.com/)
Blog: http://mobile-thoughts.blogspot.com/

  • Login to reply to this topic.