From: peter on
Hi
Shared library is used to save disk space, not memory space. If you
load two different programs and these two programs are linked with the
same shared library. That shared library exist in memory twice. Right?
thanks
from Peter (cmk128(a)hotmail.com)
From: Alexei A. Frounze on
On Apr 16, 11:25 pm, peter <cmk...(a)gmail.com> wrote:
> Hi
>   Shared library is used to save disk space, not memory space. If you
> load two different programs and these two programs are linked with the
> same shared library. That shared library exist in memory twice. Right?

Under certain conditions, there will be just one copy of it
everywhere.
Typical conditions for that:
- the library's code either appears at the same virtual address in
both programs in memory or it's position-independent
- the library contains no modifiable data, only constants; all
modifiable stuff belongs to programs, their stacks and thread-local-
storage (if any)
- just one version of the library exists :)

Alex
From: Alexei A. Frounze on
On Apr 17, 12:01 am, "Alexei A. Frounze" <alexfrun...(a)gmail.com>
wrote:
> On Apr 16, 11:25 pm, peter <cmk...(a)gmail.com> wrote:
>
> > Hi
> >   Shared library is used to save disk space, not memory space. If you
> > load two different programs and these two programs are linked with the
> > same shared library. That shared library exist in memory twice. Right?
>
> Under certain conditions, there will be just one copy of it
> everywhere.
> Typical conditions for that:
> - the library's code either appears at the same virtual address in
> both programs in memory or it's position-independent
> - the library contains no modifiable data, only constants; all
> modifiable stuff belongs to programs, their stacks and thread-local-
> storage (if any)
> - just one version of the library exists :)
>
> Alex

Wait, what I've just described was essentially DLLs...

Theoretically, you can still save memory even with linked libraries,
but for them to look like DLLs you'd need to still satisfy all of the
above and the library image should be identical inside of the apps,
that is, the linker shouldn't shuffle the library's code when linking.
I'd say it should be a loose linking, more or less like appending the
library to the rest of the program image and doing nothing else with
it.

Also, some relaxations w.r.t. modifiable data can be made if you use
copy-on-write.

Alex
From: peter on
On 4月17日, 下午3時01分, "Alexei A. Frounze" <alexfrun...(a)gmail.com> wrote:
> On Apr 16, 11:25 pm, peter <cmk...(a)gmail.com> wrote:
>
> > Hi
> >   Shared library is used to save disk space, not memory space. If you
> > load two different programs and these two programs are linked with the
> > same shared library. That shared library exist in memory twice. Right?
>
> Under certain conditions, there will be just one copy of it
> everywhere.
> Typical conditions for that:
> - the library's code either appears at the same virtual address in
> both programs in memory or it's position-independent
> - the library contains no modifiable data, only constants; all
> modifiable stuff belongs to programs, their stacks and thread-local-
> storage (if any)
> - just one version of the library exists :)
>
> Alex

thanks, what linux command can check the library with modifiable data
or not?
From: peter on
On 4月17日, 下午3時08分, "Alexei A. Frounze" <alexfrun...(a)gmail.com> wrote:
> On Apr 17, 12:01 am, "Alexei A. Frounze" <alexfrun...(a)gmail.com>
> wrote:
>
>
>
>
>
> > On Apr 16, 11:25 pm, peter <cmk...(a)gmail.com> wrote:
>
> > > Hi
> > >   Shared library is used to save disk space, not memory space. If you
> > > load two different programs and these two programs are linked with the
> > > same shared library. That shared library exist in memory twice. Right?
>
> > Under certain conditions, there will be just one copy of it
> > everywhere.
> > Typical conditions for that:
> > - the library's code either appears at the same virtual address in
> > both programs in memory or it's position-independent
> > - the library contains no modifiable data, only constants; all
> > modifiable stuff belongs to programs, their stacks and thread-local-
> > storage (if any)
> > - just one version of the library exists :)
>
> > Alex
>
> Wait, what I've just described was essentially DLLs...
>
> Theoretically, you can still save memory even with linked libraries,
> but for them to look like DLLs you'd need to still satisfy all of the
> above and the library image should be identical inside of the apps,
> that is, the linker shouldn't shuffle the library's code when linking.
> I'd say it should be a loose linking, more or less like appending the
> library to the rest of the program image and doing nothing else with
> it.
>
> Also, some relaxations w.r.t. modifiable data can be made if you use
> copy-on-write.
>
> Alex

what is Linux do when it loads two programs with the same shared
library?
I can't find any document that mention this thing.