CLR Shared Memory, C# DLL load

D

DR

CLR Shared Memory, C# DLL load

How to share memory between CLR calls to the same C# dll? Is there some way
to know in the C# dll when the dll is loaded? Is the dll reloaded each tiem
a method is called from SQL Server or is the DLL loaded once when the C# dll
is added to sql server with CREATE ASSEMBLY?

I wold like to be able to share memory accross calls to methods on the same
C# dll is why. e.g. a Shared ArrayList or a shared Hashtable.
 
N

Nicholas Paldino [.NET/C# MVP]

DR,

Are you doing this in the same app domain? If so, then a static member
is all you need.

However, if you want to do this in different application domains, then
you can't use shared memory from C# (I think there is a way to do it in C++
with the CLI extensions, but I'm not sure). Rather, you would have to
create a service (not a literal one, but one instance which other app
domains communicate with) which will host the values and return them to the
callers.
 
W

Willy Denoyette [MVP]

DR said:
CLR Shared Memory, C# DLL load

How to share memory between CLR calls to the same C# dll? Is there some
way to know in the C# dll when the dll is loaded? Is the dll reloaded each
tiem a method is called from SQL Server or is the DLL loaded once when the
C# dll is added to sql server with CREATE ASSEMBLY?

I wold like to be able to share memory accross calls to methods on the
same C# dll is why. e.g. a Shared ArrayList or a shared Hashtable.


I'm not clear on what you mean with shared memory, are you talking about
memory mapped files, or something else?. I'm also not clear on what you are
trying to achieve here.
To answer the remainder of your question, whenever you call into a managed
function or SP for the first time, the host (SQL Server) loads the CLR which
at his turn creates an Application Domain (AD) and loads your registered
assembly into that AD. The CLR keeps this AD loaded, and with it, the loaded
assemblies, until something really bad happens or until the DB is taken
off-line. The SQL/CLR can reload the AD whenever something bad happens in
your code, but otherwise the assemblies stay loaded until the server stops
or until the DB gets detached. That means that once you have called into a
function/sp your (Jitted) code remains loaded in the SQL Server process
space.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top