473,324 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Passing a DLL vs. Reinstantiating it

Tom
I have a main VB.NET program which instantiates a number of other VB.NET
DLLs. This DLLs all use routines from a 'base' DLL (which contains a number
of common routines); so currently I reinstantiate that 'base' DLL in every
one of my called DLLs.

The question is: Would it be better if I instantiated the 'base' DLL in the
main program, then passed a reference of the 'base' to each of my other
DLLs? Or is .NET smart enough to use same copy of the 'base' DLL when it
gets instantiated in each of my DLLs? (in other words, even though the same
'base' DLL is instantiated many times in different DLLs, VB.NET keeps only
one copy in memory of the 'base' DLL and they all share that copy).

Just wondering if going through the work of passing a reference to my 'base'
DLL is worth it.... Thanks.

Tom
Nov 20 '05 #1
2 1323
Of course not. All the instances are different. Each one might have
different properties set, etc, and that woudl make it behave differently.
If all instances of the same class, were actually just one instance
internally, then nothing would ever work. Imagine having 2 string
variables - but then somehow internally, .NET would treat them as one? How
would that work?

If the methods in your class don't depend on class state, and just on the
arguments to each of the methods, then you can make them all Shared. This
means you call the method through the class name itself, as opposed to
through an instance of that class. That means that no instance of the class
is ever instantiated, and you are not wasting resources by creating objects
that don't really need to be there.

"Tom" <to*@nospam.com> wrote in message
news:On**************@tk2msftngp13.phx.gbl...
I have a main VB.NET program which instantiates a number of other VB.NET
DLLs. This DLLs all use routines from a 'base' DLL (which contains a number of common routines); so currently I reinstantiate that 'base' DLL in every
one of my called DLLs.

The question is: Would it be better if I instantiated the 'base' DLL in the main program, then passed a reference of the 'base' to each of my other
DLLs? Or is .NET smart enough to use same copy of the 'base' DLL when it
gets instantiated in each of my DLLs? (in other words, even though the same 'base' DLL is instantiated many times in different DLLs, VB.NET keeps only
one copy in memory of the 'base' DLL and they all share that copy).

Just wondering if going through the work of passing a reference to my 'base' DLL is worth it.... Thanks.

Tom

Nov 20 '05 #2
Of course not. All the instances are different. Each one might have
different properties set, etc, and that woudl make it behave differently.
If all instances of the same class, were actually just one instance
internally, then nothing would ever work. Imagine having 2 string
variables - but then somehow internally, .NET would treat them as one? How
would that work?

If the methods in your class don't depend on class state, and just on the
arguments to each of the methods, then you can make them all Shared. This
means you call the method through the class name itself, as opposed to
through an instance of that class. That means that no instance of the class
is ever instantiated, and you are not wasting resources by creating objects
that don't really need to be there.

"Tom" <to*@nospam.com> wrote in message
news:On**************@tk2msftngp13.phx.gbl...
I have a main VB.NET program which instantiates a number of other VB.NET
DLLs. This DLLs all use routines from a 'base' DLL (which contains a number of common routines); so currently I reinstantiate that 'base' DLL in every
one of my called DLLs.

The question is: Would it be better if I instantiated the 'base' DLL in the main program, then passed a reference of the 'base' to each of my other
DLLs? Or is .NET smart enough to use same copy of the 'base' DLL when it
gets instantiated in each of my DLLs? (in other words, even though the same 'base' DLL is instantiated many times in different DLLs, VB.NET keeps only
one copy in memory of the 'base' DLL and they all share that copy).

Just wondering if going through the work of passing a reference to my 'base' DLL is worth it.... Thanks.

Tom

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Dave | last post by:
I'm currently working on a small project (admitedly for my CS class) that compares the time difference between passing by value and passing by reference. I'm passing an array of 50000 int's. ...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
9
by: Just Me | last post by:
PARAFORMAT2 is a structure that SendMessage will return stuff in. Is the "ref" correct or since only a pointer is being passed should it be by value? Suppose I was passing data rather then...
8
by: Dennis Myrén | last post by:
I have these tiny classes, implementing an interface through which their method Render ( CosWriter writer ) ; is called. Given a specific context, there are potentially a lot of such objects,...
0
by: Tom | last post by:
I have a main VB.NET program which instantiates a number of other VB.NET DLLs. This DLLs all use routines from a 'base' DLL (which contains a number of common routines); so currently I...
22
by: Arne | last post by:
How do I pass a dataset to a webservices? I need to submit a shoppingcart from a pocket PC to a webservice. What is the right datatype? II have tried dataset as a datatype, but I can't get it to...
6
by: MSDNAndi | last post by:
Hi, I get the following warning: "Possibly incorrect assignment to local 'oLockObject' which is the argument to a using or lock statement. The Dispose call or unlocking will happen on the...
12
by: Andrew Bullock | last post by:
Hi, I have two classes, A and B, B takes an A as an argument in its constructor: A a1 = new A(); B b = new B(a1);
4
by: Deckarep | last post by:
Hello fellow C# programmers, This question is more about general practice and convention so here goes: I got into a discussion with a co-worker who insisted that as a general practice all...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.