473,473 Members | 1,460 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

constructor constraint in C# 2.0

Hi

Im using Whidbey version 8.0.30703.27, working with C# 2.0.

I discovered that creating an object through the
constructor constraint is a sloooow process... Is this
just because I'm working on a beta version, or is there a
deeper cause for this?

My time measurements for creating 1 million objects is 6.7
seconds using the new constraint versus 0.2 seconds using
an abstract factory....

never mind the other strange constraint in the example, it
shouldn't make a difference :)

----- new constrint ------
abstract class A<FB> where FB : A<FB>, new()
{
int number = 1000000;
FB[] myArray;
public void generate()
{
myArray = new FB[number];
for (int i = 0; i < number; i++)
{
myArray[i] = new FB();
}
}
}

class B : A<B>
{
}

class Control
{
public static void Main()
{
B b = new B();
DateTime start = DateTime.Now;
b.generate();
DateTime stop = DateTime.Now;
TimeSpan res = stop.Subtract(start);
Console.WriteLine(res);
}
}

------- abstract factory ---------
abstract class A<FB> where FB: A<FB>
{
abstract public A_Fact<FB> fact();
int number = 1000000;
FB[] myArray;
public void generate()
{
myArray = new FB[number];
for (int i = 0; i < number; i++)
{
myArray[i] = fact().newA();
}
}
}

abstract class A_Fact<FB> where FB : A<FB>
{
abstract public FB newA();
}

class B_Fact : A_Fact<B>
{
public static B_Fact f = new B_Fact();
public override B newA() { return new B(); }
}

class B : A<B>
{
public override A_Fact<B> fact()
{
return B_Fact.f;
}
}

class Control
{
public static void Main()
{
B b = new B();
DateTime start = DateTime.Now;
b.generate();
DateTime stop = DateTime.Now;
TimeSpan res = stop.Subtract(start);
Console.WriteLine(res);
}
}
Nov 16 '05 #1
1 1516
Hmmm... version 8.0.30703.27 is not the latest Beta1.

Anyway, I'm sure you would get better answers when posting whidbey questions
to the whidbey generics NG' - microsoft.private.whidbey.generics

Willy.

"Ole Andre Karlson" <ol****@ifi.uio.no> wrote in message
news:0f****************************@phx.gbl...
Hi

Im using Whidbey version 8.0.30703.27, working with C# 2.0.

Nov 16 '05 #2

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

Similar topics

0
by: Dmitry Martynov | last post by:
What if I have some special constructors and do not have a default constructor. It seems to be very useful when I do not want to forget to initialize some fields properly. As I have understood...
1
by: Dmitry Martynov | last post by:
What if I have some special constructors and do not have a default constructor. It seems to be very useful when I do not want to forget to initialize some fields properly. As I have understood...
9
by: Alon Fliess | last post by:
Hi I am trying to write a generic class that instantiates the generic type, but I can not find the correct way to give it the constructor constraint. For example: In C#: class X<T> where...
2
by: gilbert | last post by:
Hello. I am trying to use c# generic to define a class. class MyClass<Twhere T: new(){ } In this definition, MyClass can create T objects with a default constructor. Is there any way to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.