|
|
Ah yes. The double lock check - which is unnecessary in C#. This same code can be accomplished using the static keyword:
public sealed class LoadBalancer()
{
private static readonly LoadBalancer _instance = new LoadBalancer();
private LoadBalancer() {}
public static LoadBalancer Instance
{
get { return _instance ; }
}
} The key here is that the CLR initializes the _instance member the first time this class is used. As you can see, this code is significantly simpler, and it solves the same problem in a different fashion - plus it's slightly more efficient.
|
|
|
|
|
This holds for single threaded applications only.
|
|
|
|
|
Assume you want to allow only one instance of the LoadBalancer class. The usual Singleton Pattern assures exactly that, except that it holds for single threaded applications only.
Assume you have more than one threads (e.g. A and B), both working with LoadBalancer. Then it could happen that, while thread A is just creating an instance of the LoadBalancer, the thread scheduler decides thread B to run which also wants to create an instance of LoadBalancer. This results in two instances of the LoadBalancer to be created. That's why you have to lock the instanciation so that only one thread at a time can create the instance.
|
|
|
|
|
what is the difference between Compile Time Polymorphism & Run Time Polymorphism ?
|
|
|
|
|
See here.[^]
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
That was simply awesome
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
yup. My favorite cluebat for trivial homework questions. It's much quicker than writing pseudocode to bludgeon them, although I try not to use it too often.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
I use it too, as do others.
Kevin
|
|
|
|
|
wow
good answer, deserved my 5
Yusuf
|
|
|
|
|
|
Yowza! You scared the poor guy away!
/ravi
|
|
|
|
|
Ravi Bhavnani wrote: Yowza! You scared the poor guy away!
Nope... see a few posts above
|
|
|
|
|
Ram_Bytes wrote: what is the difference between Compile Time Polymorphism & Run Time Polymorphism
The same as Overloading and Overriding have.
I hope, you know what these two terms mean.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Polymorphism means that the certain functions can take different forms (take different actions), depending on how they are called.
With compile-time polymorphism, some of these actions can be determined at compile-time such as method overloading, operator overloading, and templates. The compiler knows how to build and call each instance of the method because they are all clearly defined in the code. This is also known as static polymorphism, static binding, or early binding.
Sometimes run-time polymorphism has to be used because the form that the method will take cannot be determined until run-time, such as virtual functions and function overriding through inheritance. This is also known as dynamic polymorphism, dynamic binding, or late binding.
By the way, in Java, method overloading and method overriding are both implemented during run-time only.
Enjoy,
Robert C. Cartaino
|
|
|
|
|
Ram_Bytes wrote: what is the difference between Compile Time Polymorphism & Run Time Polymorphism ?
<code>Compile </code>Time Polymorphism
<code>Run </code>Time Polymorphism
led mike
|
|
|
|
|
How do I change the datagrid.readonly property at run time
Sree
|
|
|
|
|
Double postingwont help you do that.
When do you want to change this attribute??
"If you had to identify, in one word, the reason why the human race has not achieved, and never will achieve, its full potential, that word would be 'meetings'." - Dave Barry
|
|
|
|
|
Why two Posts?
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
unlike C/++ you can't just cast const away anytime you find it annoying.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
How do I change the datagrid.readonly property at run time.
Please help me in this regard.
|
|
|
|
|
look the meaning of "readonly" in the dictionary.
Yusuf
|
|
|
|
|
Hi Guys,
Im stuck in a weird problem, and hope the experts here can help me.
I have a C# VS2005 project. I call a Borland C DLL in it, using:
System.Runtime.InteropServices.DllImport(......
to get a function 'GetSearchResults' from the DLL like this:
int Result = Module1.GetSearchResults (handle, ref DeviceInfo, 1);
Module1: an internal sealed class where the DLLImport is done and device_info_t is declared.
DeviceInfo: is a object of a structure called device_info_t . I am supposed to get the Search-Result back in this structure.
The C function looks like this:
int GetSearchResults(const handle_t handle, device_info_t results[], const size_t count);
Now, when I run this code, I get a 'System.AccessViolationException', saying 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt'.
Does anyone have an idea, whats happening, whats causing this error?
Thank you soo much guys...
|
|
|
|
|
indogerman wrote: Does anyone have an idea, whats happening, whats causing this error?
Assuming the Borland C DLL works properly and is NOT the source of the error then probably the Interop (PInvoke) has not been developed correctly. However since you did not post any of it we have no way of knowing.
led mike
|
|
|
|
|
How do you declare the device_info_t struct into the c# project? Do you use the StructLayout attribute? Are there const size arrays into struct?
|
|
|
|