473,324 Members | 1,678 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.

Static Functions in Multi-user web app


Is there any performance considerations or any other concerns about having a
Class with private constructor and all static functions? One particular
function in question creates a few new instances of COM objects (through COM
Interop), and makes lots of calls to these unmanaged COM objects.
There's a small debate in our team if having this portion of code inside
static function is appropriate for this multi-user web application that will
probably server many simultaneous requests. Should this logic be inside an
instance class?

Feb 6 '06 #1
6 1450
I would imagine you need to make sure that accesses to the COM objects are
thread safe, since you only have one instance of those. If you do, that may
end up being a bottleneck when you have many users hitting the system, which
would mean you need to make all your methods instance methods using separate
instances of the COM objects.

"WebMatrix" <We*******@discussions.microsoft.com> wrote in message
news:05**********************************@microsof t.com...

Is there any performance considerations or any other concerns about having
a
Class with private constructor and all static functions? One particular
function in question creates a few new instances of COM objects (through
COM
Interop), and makes lots of calls to these unmanaged COM objects.
There's a small debate in our team if having this portion of code inside
static function is appropriate for this multi-user web application that
will
probably server many simultaneous requests. Should this logic be inside an
instance class?

Feb 6 '06 #2
WebMatrix,

If the static function is not modifying state, then I don't see why not.
However, I do think that using the COM objects will be a problem. Not
because of the static nature of the functions, but you have to be sure that
you have set up the threading correctly to use COM objects in your project
(you need to set AspCompat = true in order for COM objects to work correctly
in ASP.NET, and you are going to take a little bit of a performance hit, I
believe).

Given all that, if your functions are static, and you are not modifying
any stored state, then there is no reason you can't do this. The problem
inherently doesn't come from whether or it is static or an instance method.
If you have to share the state between calls to the method (either static
state, or the state of the instance), and multiple threads are going to hit
it (like in a web environment), then you are going to have to synchronize
access to that resource.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"WebMatrix" <We*******@discussions.microsoft.com> wrote in message
news:05**********************************@microsof t.com...

Is there any performance considerations or any other concerns about having
a
Class with private constructor and all static functions? One particular
function in question creates a few new instances of COM objects (through
COM
Interop), and makes lots of calls to these unmanaged COM objects.
There's a small debate in our team if having this portion of code inside
static function is appropriate for this multi-user web application that
will
probably server many simultaneous requests. Should this logic be inside an
instance class?

Feb 6 '06 #3
The COM object itself has no state. All methods of this COM object are of
"request/response" nature. Each call to a static function creates COM objects
and destroy them when it's done with them. Am I understaning correctly that
each call to static function will work with its own instance of COM object
and its data? So thread safety would not be a problem?

"Marina Levit [MVP]" wrote:
I would imagine you need to make sure that accesses to the COM objects are
thread safe, since you only have one instance of those. If you do, that may
end up being a bottleneck when you have many users hitting the system, which
would mean you need to make all your methods instance methods using separate
instances of the COM objects.


Thank you for your reply. There's no
Feb 6 '06 #4
WebMatrix,

Yes, each call to the COM object will be safe, but you have to consider
the apartment model. You have to make sure that the calls are on pages/web
services where AspCompat is set to true, so that the apartment model can be
set up correctly.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"WebMatrix" <We*******@discussions.microsoft.com> wrote in message
news:17**********************************@microsof t.com...
The COM object itself has no state. All methods of this COM object are of
"request/response" nature. Each call to a static function creates COM
objects
and destroy them when it's done with them. Am I understaning correctly
that
each call to static function will work with its own instance of COM object
and its data? So thread safety would not be a problem?

"Marina Levit [MVP]" wrote:
I would imagine you need to make sure that accesses to the COM objects
are
thread safe, since you only have one instance of those. If you do, that
may
end up being a bottleneck when you have many users hitting the system,
which
would mean you need to make all your methods instance methods using
separate
instances of the COM objects.


Thank you for your reply. There's no

Feb 6 '06 #5

If the static function is not modifying state, then I don't see why not.
However, I do think that using the COM objects will be a problem. Not
because of the static nature of the functions, but you have to be sure that
you have set up the threading correctly to use COM objects in your project
(you need to set AspCompat = true in order for COM objects to work correctly
in ASP.NET, and you are going to take a little bit of a performance hit, I
believe).

Given all that, if your functions are static, and you are not modifying
any stored state, then there is no reason you can't do this. The problem
inherently doesn't come from whether or it is static or an instance method.
If you have to share the state between calls to the method (either static
state, or the state of the instance), and multiple threads are going to hit
it (like in a web environment), then you are going to have to synchronize
access to that resource.

Hope this helps.

Thank you. It does help.

Right, no state between the calls. Like I said in a previous post; it's
"request/response" style calls.
but you have to be sure that you have set up the threading correctly to use COM objects in your project
(you need to set AspCompat = true in order for COM objects to work correctly
in ASP.NET


Could you elaborate or point to some URL.

Feb 6 '06 #6
Ok, I was a little mistaken, you can't really use AspCompat, that's only
for pages in ASP.NET. Rather, you have to host your controls in COM+. The
following KB article tells you how to do it:

http://support.microsoft.com/default...;en-us;Q303375
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"WebMatrix" <We*******@discussions.microsoft.com> wrote in message
news:01**********************************@microsof t.com...

If the static function is not modifying state, then I don't see why
not.
However, I do think that using the COM objects will be a problem. Not
because of the static nature of the functions, but you have to be sure
that
you have set up the threading correctly to use COM objects in your
project
(you need to set AspCompat = true in order for COM objects to work
correctly
in ASP.NET, and you are going to take a little bit of a performance hit,
I
believe).

Given all that, if your functions are static, and you are not
modifying
any stored state, then there is no reason you can't do this. The
problem
inherently doesn't come from whether or it is static or an instance
method.
If you have to share the state between calls to the method (either static
state, or the state of the instance), and multiple threads are going to
hit
it (like in a web environment), then you are going to have to synchronize
access to that resource.

Hope this helps.


Thank you. It does help.

Right, no state between the calls. Like I said in a previous post; it's
"request/response" style calls.
but you have to be sure that you have set up the threading correctly to
use COM objects in your project
(you need to set AspCompat = true in order for COM objects to work
correctly
in ASP.NET


Could you elaborate or point to some URL.

Feb 6 '06 #7

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

Similar topics

6
by: mflanagan | last post by:
I have unmanaged C++ program that will load a managed C++ dll and then call a function in that dll. The managed C++ routine will call some C# routines. The unmanaged C++ main program will make...
9
by: Seenu | last post by:
Is it safe to create a static function in a multi threaded application ? As an example, I have a function that logs errors ,exceptions and some informational data public static void Log(....) {...
2
by: David | last post by:
I have a static method in the dll that looks like this public static int myStaticFunction(int input){ } My question is, should I use a mutex inside the function to ensure that the function is...
10
by: Simon | last post by:
Hi, I have something like // // common.h const unsigned long m_dwStyle = 0x123; // // common.h
18
by: Ronald Bruck | last post by:
I have several routines which are used millions of times in my programs, using the Gnu multi-precision software's floating-point reals (see <http://www.swox.se/gmp>). These are of type mpf_t, and...
2
by: Random | last post by:
Here's a design question I'm curious to know if anyone here has wrestled with before... I'm writing my data access methods in classes in the App_Code directory. I know that I can easily...
5
by: Sam.Gundry | last post by:
Hi, I wish to share an object through a bunch of functions without declaring it globally. I have achieved this through the following function: VideoReceiver* getReceiver() { static...
55
by: Zytan | last post by:
I see that static is more restricted in C# than in C++. It appears usable only on classes and methods, and data members, but cannot be created within a method itself. Surely this is possible in...
14
by: subramanian100in | last post by:
In the following link, http://www.c-faq.com/malloc/retaggr.html The following ANSWER is given to a question(comp.lang.c FAQ list · Question 7.5a) : Whenever a function returns a pointer, make...
3
by: PencoOdStip | last post by:
What are macros,virtual functions and what static means? I don't have time to read a book,i have to finish a simple plugin till tomorow morning to my first client and i need to know what these...
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...
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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.