run-time dynamic linking and static data. 
Author Message
 run-time dynamic linking and static data.

Is there a good place to read about static data and dynamic linking? I've been
searching in MSDN, but all I find is repeated quotes such as  "Every process
that loads the DLL maps it into its virtual address space" but I can find no
actual detailed description of what this means, or how it works in conjunction
with static data.

I'm writing dll's, that are dynamically loaded by an IIS extension DLL at
runtime, they are all compiled using the DLL versions of the runtime library,
(/MDd for debug and /MD for release) still they do _not_ share their static
data. Static data in baseclasses as well as Loki singletons are replicated for
each DLL. Can I fix this? How?

/Magnus Lidbom



Sun, 24 Jul 2005 22:36:12 GMT  
 run-time dynamic linking and static data.

Quote:

> Is there a good place to read about static data and dynamic linking?
> I've been searching in MSDN, but all I find is repeated quotes such
> as  "Every process that loads the DLL maps it into its virtual
> address space" but I can find no actual detailed description of what
> this means, or how it works in conjunction with static data.

> I'm writing dll's, that are dynamically loaded by an IIS extension
> DLL at runtime, they are all compiled using the DLL versions of the
> runtime library, (/MDd for debug and /MD for release) still they do
> _not_ share their static data. Static data in baseclasses as well as
> Loki singletons are replicated for each DLL. Can I fix this? How?

In general -

1. Move the static data into a single DLL.
2. Link all of your code into a single DLL.
3. Use a runtime facility to allocate shared "static" data (e.g. in a
file mapping) and have your classes use that.

-cd



Sun, 24 Jul 2005 22:52:38 GMT  
 run-time dynamic linking and static data.



Quote:

> > Is there a good place to read about static data and dynamic linking?
> > I've been searching in MSDN, but all I find is repeated quotes such
> > as  "Every process that loads the DLL maps it into its virtual
> > address space" but I can find no actual detailed description of what
> > this means, or how it works in conjunction with static data.

> > I'm writing dll's, that are dynamically loaded by an IIS extension
> > DLL at runtime, they are all compiled using the DLL versions of the
> > runtime library, (/MDd for debug and /MD for release) still they do
> > _not_ share their static data. Static data in baseclasses as well as
> > Loki singletons are replicated for each DLL. Can I fix this? How?

> In general -

> 1. Move the static data into a single DLL.

This might be doable, but given the poor quality of the documentation I've
found on how, I don't know. Any pointers to good documentation on using
dynamic linking as well as how static data relates to it would be very much
appreciated.

Quote:
> 2. Link all of your code into a single DLL.

No can do, the dlls are loaded by the IIS API extension by name, it must be:
"one subclass, one dll". To my great frustration there's nothing I can do
about that.

Quote:
> 3. Use a runtime facility to allocate shared "static" data (e.g. in a
> file mapping) and have your classes use that.

How do you mean?

The static data looks something like this:
class foo
{
   static std::set<Loki::TypeInfo> registeredSubClasses;
    .......

Quote:
};

where each dll subclasses foo.

Thanks for the swift reply :)

/Magnus Lidbom



Sun, 24 Jul 2005 23:03:38 GMT  
 run-time dynamic linking and static data.
I think it would be easiest if your class foo would incorporate some form of
interprocess communication, so that you don't use 'real' static variables,
but fake them by using variables that you access via interprocess
communication.

you can use either some form of sockets based interprocess communication
(search msdn for samples)

or

have a look at using #pragma data_seg. That's probably the
simplest method for simple variables. See "How do I share data in my
DLL with an application or with other DLLs?" in the MSDN
documentation. the disadvantage is that you have to synchronize access
yourself.

sometime ago there was a post about it. thats were this info is coming from.

hope this helps,
    Bruno.


Quote:




> > > Is there a good place to read about static data and dynamic linking?
> > > I've been searching in MSDN, but all I find is repeated quotes such
> > > as  "Every process that loads the DLL maps it into its virtual
> > > address space" but I can find no actual detailed description of what
> > > this means, or how it works in conjunction with static data.

> > > I'm writing dll's, that are dynamically loaded by an IIS extension
> > > DLL at runtime, they are all compiled using the DLL versions of the
> > > runtime library, (/MDd for debug and /MD for release) still they do
> > > _not_ share their static data. Static data in baseclasses as well as
> > > Loki singletons are replicated for each DLL. Can I fix this? How?

> > In general -

> > 1. Move the static data into a single DLL.
> This might be doable, but given the poor quality of the documentation I've
> found on how, I don't know. Any pointers to good documentation on using
> dynamic linking as well as how static data relates to it would be very
much
> appreciated.

> > 2. Link all of your code into a single DLL.
> No can do, the dlls are loaded by the IIS API extension by name, it must
be:
> "one subclass, one dll". To my great frustration there's nothing I can do
> about that.

> > 3. Use a runtime facility to allocate shared "static" data (e.g. in a
> > file mapping) and have your classes use that.

> How do you mean?

> The static data looks something like this:
> class foo
> {
>    static std::set<Loki::TypeInfo> registeredSubClasses;
>     .......
> };

> where each dll subclasses foo.

> Thanks for the swift reply :)

> /Magnus Lidbom



Sun, 24 Jul 2005 23:22:57 GMT  
 run-time dynamic linking and static data.


Quote:
> I think it would be easiest if your class foo would incorporate some form of
> interprocess communication, so that you don't use 'real' static variables,
> but fake them by using variables that you access via interprocess
> communication.

> you can use either some form of sockets based interprocess communication
> (search msdn for samples)

> or

> have a look at using #pragma data_seg. That's probably the
> simplest method for simple variables. See "How do I share data in my
> DLL with an application or with other DLLs?" in the MSDN
> documentation.

Thanks Bruno. I'll look those up.

/Magnus



Sun, 24 Jul 2005 23:26:41 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. static and dynamic linking: runtime

2. Run-Time Dynamic Linking

3. Dynamic linking or run time loading

4. dynamic link to static link...

5. dynamic link -> static link

6. Error linking static MFC and static C/C++ runtime

7. PRB: LNK2005 Errors When Link C Run-Time Libraries Are Linked Before MFC Libraries (Q148652)

8. Static vs. Dynamic linking

9. static or dynamic linked which is better for daemon

10. Static vs Dynamic linking

11. ATL.DLL - static or dynamic linking

12. Static vs Dynamic link

 

 
Powered by phpBB® Forum Software