473,397 Members | 1,960 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,397 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 1856
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.