|
bigchump wrote:
Going wrong? I don't think so.
Going wrong with the C#. Nobody is disputing the performance of your other program. Sheesh.
bigchump wrote: I never liked c++ and hate to use it but I'm becoming desperate and need some advice in the King's ENGLISH I can understand.
Granted the link I sent you is a mildly technical post, but I think it's the direction you should take. I suggest reading through it again and try to make some sense of it. I don't think there's an easier answer with the performance you want. I appreciate your plight here, but you'll have to take the bull by the horns and make a better attempt at learning how to use the language. If you don't have reference material, I highly suggest getting CLR via C# by Jeffrey Richter, and Programming Visual C# 2005: The Language by Donis Marshall.
If you posted the code that's loading the data from the binary file, it may be useful.
Scott P
“It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.”
-Edsger Dijkstra
|
|
|
|
|
Hi Carbon:
"Going wrong with the C#. Nobody is disputing the performance of your other program. Sheesh."
Brother, I think you're missing the point. When should a 32 bit app outperform a 64????????
Somethings gotta be wrong somewhere. Maybe my head's screwed on sideways. That's a possibility I don't discount.
I PORTED ALL MY APPS TO C# AND ONLY ONE IS CAUSING THIS MISERY.
When I say all, I mean over 14 different apps and only one doesn't work properly.
Even the one with problems works OK just EXTREMELY SLOW. But slow is a killer in my business.
What I need is a way to read/write structs/classes to file without the MAJOR OVERHEAD.
sorry if I sounded hostile - I just need some help without any wisecracks..
bigchump
|
|
|
|
|
"If you posted the code that's loading the data from the binary file, it may be useful."
Here's the code but the problem is not loading data but the SIZE of the file that is created.
public void DeSerializeNow()
{
header c1=new header(); //change to header - horse - results
horse[] c2=new horse[29];
Stream s=File.Open(@"C:\baduga\manure.tmp",FileMode.Open);
BinaryFormatter b=new BinaryFormatter();
while(true)
{
try
{
c1=(header)b.Deserialize(s);
label1.Text+=c1.track+" "+c1.poly+" "+c1.entries+" "+c1.par2f+" "+c1.par4f+" "+c1.par6f+" "+c1.parspeed+"\n";
for(int y=0;y<c1.entries;y++)
{
c2[y]=(horse)b.Deserialize(s);
label1.Text+=c2[y].post+",";
}
label1.Text+="\n";
}
catch
{
s.Close();
break;
}
}
}
Note the label stuff is just for debugging - it ain't used in real life...
thanx
bigchump
|
|
|
|
|
bigchump wrote: run about 3000 "if" statements
Are they all in one function? Could you post a code snippet with 10-20 of these statements?
|
|
|
|
|
If you're not an expert after 20 years of doing it, you should hire someone.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
OK John,
If you can make my 64bit C# app run faster than my c++ 32 bit one you can write your own ticket.
LITERALLY--
bichump
|
|
|
|
|
Hi,
I've read the rest of this thread, and hopefully I understand what your problem is. As far as I can tell, your main problem is the size of the file created by your program. (Please correct me if I am wrong)
Firstly, I suspect you are using XML serialization, this will likely explain the size. Can you post the code you use to create the file, and a small sample (just a few lines) from an output file so I can take a look at what's going on.
If my guess is correct, and you are using XML serialization, you might consider using binary serialization instead. This will almost certainly drastically reduce the size of the saved file. If you're not sure how to do this, post your code and I'll point out what needs to be changed.
Simon
Simon
|
|
|
|
|
Hi Simon!
Yes, the file size is at least 16x larger than it should be!
I am using binary serialization as far as I know.
I already tried using char arrays (like the original app) instead of strings.
That doesn't help at all.
Here's the start of the code that writes the first small class:
public void SerializeNow()
{
header c=new header();
Stream s=File.Open(@"C:\baduga\manure.tmp",FileMode.Append);
BinaryFormatter b=new BinaryFormatter();
FileStream hread=new FileStream(@"c:\baduga\races.txt",FileMode.Open); //read races.txt
StreamReader hread1=new StreamReader(hread);
string temp;
string[] t=new string[1435];
int a=0,x=0,y;
while((temp=hread1.ReadLine())!=null)
{
if(temp.StartsWith("JJGENDRACE"))
{
c.entries=a;
b.Serialize(s,c);
for(y=0;y<c.entries;y++)>
{
b.Serialize(s,h[y]);
}
a=x=0;
}
else
{
t[x]=temp;
if(t[x]=="") t[x]="0";
x++;
if(x==1435)
{
if(a==0)
{
c.track=t[0];
c.date=t[1];
c.race=t[2];
c.distance=int.Parse(t[5].Trim('-'));
c.distanceD=c.distance/220;
c.surface=t[6];
c.type=t[8];
c.sex=t[9];
c.formtype=t[10];
c.purse=int.Parse(t[11]);
c.purseD=c.purse/5000;
if(c.purseD>50) c.purseD=50;
c.claimprice=int.Parse(t[12]);
c.trackrecord=float.Parse(t[14]);
c.simulT=t[20];
c.simulR=t[21];
c.breed=t[22];
c.poly=t[24];
c.par2f=int.Parse(t[213]);
c.par4f=int.Parse(t[214]);
c.par6f=int.Parse(t[215]);
c.parspeed=int.Parse(t[216]);
c.parLf=int.Parse(t[217]);
}
|
|
|
|
|
With serialzation, all public members of the object are serialized. Is this what you want? If you have some members you don't want to be serialized you can mark them with attributes to prevent this.
Check that your problem is not with your code logic. Step through carefully and check that you aren't accidently serializing more than you meant too. (Like the same object twice).
If you switch to xml serialization you can look at the data and check that only the correct stuff is there. Then once your happy with the data being outputed, switch back to binary again.
Comments on the code (Numbers indicate line in code I'm talking about):
1) The for loop here is incomplete. I'm assuming you just want to loop through all objects in the array h, buy maybe more code is missing.
2) the variable a is never assigned a value other than 0. What is it's purpose?
3) For every line read in that starts with JJGENDRACE you are serializing the whole of the array h. I don't know whats in this array as you haven't included it's defination or population code, but why are you serializing the same array every time? This will be a huge waste of space if you are just serializing the same data over and over again.
General comment: The variable names c, s, b, t, a, x and y are not very useful. If you used more descriptive veriable names that would help other people to read your code.
public void SerializeNow()
{
header c = new header();
Stream s = File.Open(@"C:\baduga\manure.tmp", FileMode.Append);
BinaryFormatter b = new BinaryFormatter();
FileStream hread = new FileStream(@"c:\baduga\races.txt", FileMode.Open);
StreamReader hread1 = new StreamReader(hread);
string temp;
string[] t = new string[1435];
int a = 0, x = 0, y;
while ((temp = hread1.ReadLine()) != null)
{
if (temp.StartsWith("JJGENDRACE"))
{
2) c.entries = a;
b.Serialize(s, c);
1) for (y = 0; y
{
3) b.Serialize(s, h[y]);
}
a = x = 0;
}
else
{
t[x] = temp;
if (t[x] == "")
t[x] = "0";
x++;
if (x == 1435)
{
if (a == 0)
{
c.track = t[0];
c.date = t[1];
c.race = t[2];
c.distance = int.Parse(t[5].Trim('-'));
c.distanceD = c.distance / 220;
c.surface = t[6];
c.type = t[8];
c.sex = t[9];
c.formtype = t[10];
c.purse = int.Parse(t[11]);
c.purseD = c.purse / 5000;
if (c.purseD > 50)
c.purseD = 50;
c.claimprice = int.Parse(t[12]);
c.trackrecord = float.Parse(t[14]);
c.simulT = t[20];
c.simulR = t[21];
c.breed = t[22];
c.poly = t[24];
c.par2f = int.Parse(t[213]);
c.par4f = int.Parse(t[214]);
c.par6f = int.Parse(t[215]);
c.parspeed = int.Parse(t[216]);
c.parLf = int.Parse(t[217]);
}
}
}
}
}
Simon
|
|
|
|
|
For some reason it seems that I've got difficulties to understand the logic of the web service:
I need that a webpage or an application on client side will validate user's details (username, password). Validation is through db that seats on a server application. I want that the procedure will be:
calling a validation method through web service that will use the server's db. I understand how to connect the client or the website to the web service but don't understand how the web service connects to the server to use his db (or to call a function on the server that will do that).
Can someone help please?
thanks
y
|
|
|
|
|
IF it's a webpage, use AJAX, you can't call a webservice from the client. Unless you want to do it from the server, of course.
The webservice uses a standard mechanism to make requests via HTTP. It's all hidden from you, that's kind of the point.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
thanks Christian,
but to sharpen my misunderstanding :
if i want to use a function that on my server with an application that seats in the client computer :
1.i need a webrefference to the webservice in my client's application to create an instance of it right?
2. the webservice shld have a method that invokes method on the server
so how do i connect to the method on the server with the webservice (using a dll?)
sorry if i'm all upside down ...
|
|
|
|
|
johland wrote: need a webrefference to the webservice in my client's application to create an instance of it right?
Correct.
johland wrote: the webservice shld have a method that invokes method on the server
Well, every method that is marked as such in the webservice, invokes a method on the server. Automatically. .NET hides those details from you, so you call the method and create class instances as if they were local, and the framework handles the job of making calls to the webservice and getting the result. The only difference is you need to anticipate exceptions that can occur if the framework cannot find the webservice to call.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
If you don't like my answer, ask more questions so I understand where the problem is.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
i think my first problem is phrasing
do these steps are right?
1.i want to use a method that seats on my server with another application
2.so i'm creating a webservice that call that method
this webservice will be part of the server solution so it will have access to the server db.
3.i want the client app to use this webservice so i add webreference to the client app and create instance of it and use its methods.
did i get it?
.
|
|
|
|
|
I was commenting on how my response got a 1/bad answer vote. If it wasn't you, then fair enough, but it seemed likely to me that it was.
Yes, you got it right. The framework handles all the messy stuff for you.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
sorry...didnt even noticed this feature exsits
|
|
|
|
|
I using System.Collections.HashTable to keep some information about my database.
The information that i collect in my HashTable is -
1. string ( as the key )
2. other string ( as the value )
my problem is that i want to scan the HashTable and when the value string is equal to some parameter i want to stop my scan and check the string key value.
How can i do it ?
Thanks for the help.
|
|
|
|
|
By iterating over the Keys collection.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
You can iterate the keys collection, and then retrieve and check the value for each key, reacting when you find your sought after value.
|
|
|
|
|
Hi friends........I've created a database application using C# and MS-Access........& the database part is working fine.........now is it possible to print the report directly to a PDF file from an Access database instead of using Crystal Report..........pls reply back asap..........THANKS
Thanks
|
|
|
|
|
Yes, you can buy a PDF library and use it to generate PDFs
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi All,
I have timespan object:
TimeSpan ts= new TimeSpan(0, 72, 1);
when i say :
MessageBox.Show(ts.ToString());
then i get: 01:12:02
What is that means?? 1 days, 12 hours and 2 minutes???
Thanx.
|
|
|
|
|
You're using this constructor:
public TimeSpan(int hours, int minutes, int seconds);
so you've created a timespan object for 72 minutes and 1 second.
which just happens to be exactly 1 hour, 12 minutes and 1 second.
(I'm assuming you've mistyped your output. it's 1 second, not 2)
KamarBand wrote: then i get: 01:12:02
Simon
|
|
|
|
|
Can Anyone Help
How to Remove the Duplicate Key(Repeated data) in CSV or Excel file using C# .
|
|
|
|