|
public class chromo_typ
{
public string bits { get; set; }
public float fitness { get; set; }
public chromo_typ() { bits = ""; fitness = 0.0f; }
public chromo_typ(string bts, float ftns) { bits = bts; fitness = ftns; }
}
I do believe this is right.
|
|
|
|
|
the float and string member variables are straightforward and the struct should be a class in C# (unless you have good reason to use a struct). The tricky stuff comes after that.
This
chromo_typ(): bits(""), fitness(0.0f){}; is a constructor with minimal code formatting, here's an expanded version that's a bit easier on the eyes:
chromo_typ() :
bits(""),
fitness(0.0f)
{
}; That's a parameterless constructor with an initialization list (you can google that for more info). A very similar way of writing that constructor would be this:
chromo_typ()
{
bits = "";
fitness = "0.0f;
}; Now, in C++ there are subtles difference between those two versions of the function but for the purposes of the C++ -> C# conversion you needn't worry about them. This version of the function is another pretty straightforward conversion from one language to the other.
The second chromo_typ(...) line is just another constructor with some parameters. You should be able to convert that one the same way as the first
|
|
|
|
|
This is a performance issue: Struct vs. Class. I'm at that point in development where I need to make the app more stable. The program is a truck control and monitor system. Right now the app can have any number of trucks, let's say 5. Each has an engine, the shape of the information will be given later. The child form per truck has controls to change RPM, GEAR, and Pressure as well as gauges to monitor various other aspects of information being sent back to the form from the actual engine. Needless to say this makes for all trucks to be observable a little hard on one screen. This is where the truck monitor comes in, a smaller version with bear minimum, to have all trucks on screen.
I've designed where each truck gets a time slice since we're using RS-232. We're locked into this there is no negotiating this point. Each truck writes to, receives from the engine, process information, writes to file, and eventually send to monitor child form. All this occurs at 250 ms per truck.
Each truck has a monitor for mostly display and contains three controls.
As to the processing, each truck listen to incoming port, for properly formed string data, parses the data, assigns proper portion to the right variable of the engine and gauges. Such as, rpm info is place in engine.rpm_var and so on.
All this is accomplished through a loop on the parent form, MainController. This parent form has the comport portion,RS-232, here. The loop looks this:
Indiv_Truck_Cntrl tempChild = (Indiv_Truck_Cntrl)this.MdiChildren[trxx];
{
Truck_Active.Text = tempChild.Name;
Main_Serial_Port1.Write(tempChild.port_out);
test_port = Main_Serial_Port1.ReadExisting();
if (test_port == "")
{
}
else
{
Send_Truck_Info(test_port);
}
tempChild.SEND_SETTINGS_Click();
So the question here is do I use a class or a struct for the information I need, that is for Engine. Right now I have my Engine defined as:
public class Engine
{
private string c_TRUCK_ID;
public string TRUCK_ID
{
get { return c_TRUCK_ID;} set { c_TRUCK_ID = value;}
}
private string c_TRUCK_NUM;
public string TRUCK_NUM
{
get { return c_TRUCK_NUM;} set { c_TRUCK_NUM = value; }
}
private string c_TRUCK_IP;
public string TRUCK_IP
{
get { return c_TRUCK_IP;} set { c_TRUCK_IP = value;}
}
public string RPM = "RPM";
private string c_RPM_var;
public string RPM_var
{
get { return c_RPM_var;} set { c_RPM_var = value;}
}
public string GEAR = "GEAR";
private string c_GEAR_var;
public string GEAR_var
{
get { return c_GEAR_var;} set { c_GEAR_var = value;}
}
private string c_GEAR_Name;
public string GEAR_Name
{
get { return c_GEAR_Name; } set { c_GEAR_Name = value; }
}
public string OIL_PRES = "OIL PRESSSURE ENG";
private string c_OIL_PRES_var;
public string OIL_PRES_var
{
get { return c_OIL_PRES_var;} set { c_OIL_PRES_var = value;}
}
public string COOLANT_TEMP = "COOLANT TEMP ENG";
private string c_COOLANT_TEMP_var;
public string COOLANT_TEMP_var
{
get { return c_COOLANT_TEMP_var;} set { c_COOLANT_TEMP_var = value;}
}
public string BAT_VOLT = "BATTERY VOLTAGE";
private string c_BAT_VOLT_var;
public string BAT_VOLT_var
{
get { return c_BAT_VOLT_var;} set { c_BAT_VOLT_var = value;}
}
public string TRANS_OUT_RPM = "TRANSMISSION OUTPUT RPM";
private string c_TRANS_OUT_RPM_var;
public string TRANS_OUT_RPM_var
{
get { return c_TRANS_OUT_RPM_var; } set { c_TRANS_OUT_RPM_var = value; }
}
public string FUEL_PRESS = "FUEL PRESSURE ENG";
private string c_FUEL_PRESS_var;
public string FUEL_PRESS_var
{
get { return c_FUEL_PRESS_var; } set { c_FUEL_PRESS_var = value; }
}
public string LOCKUP_CONV = "LOCKUP CONVERTER";
public string c_LOCKUP_CONV_var;
public string LOCKUP_CONV_var
{
get { return c_LOCKUP_CONV_var; } set { c_LOCKUP_CONV_var = value; }
}
public string OVER_PRESS = "OVER_PRESS SETPOINT";
private string c_OVER_PRESS_var;
public string OVER_PRESS_var
{
get { return c_OVER_PRESS_var; } set { c_OVER_PRESS_var = value; }
}
public string FRAC_PRESS = "FRAC PRESSURE";
private string c_FRAC_PRESS_var;
public string FRAC_PRESS_var
{
get { return c_FRAC_PRESS_var;} set { c_FRAC_PRESS_var = value;}
}
public string PUMP_LUBE_PRESS = "PUMP LUBE PRESSURE";
private string c_PUMP_LUBE_PRESS_var;
public string PUMP_LUBE_PRESS_var
{
get { return c_PUMP_LUBE_PRESS_var;} set { c_PUMP_LUBE_PRESS_var = value;}
}
public string PUMP_LUBE_TEMP = "PUMP_LUBE TEMPERATURE";
private string c_PUMP_LUBE_TEMP_var;
public string PUMP_LUBE_TEMP_var
{
get { return c_PUMP_LUBE_TEMP_var;} set { c_PUMP_LUBE_TEMP_var = value;}
}
public string PUMP_FLOW = "PUMP FLOW RATE";
private string c_PUMP_FLOW_var;
public string PUMP_FLOW_var
{
get { return c_PUMP_FLOW_var;} set { c_PUMP_FLOW_var = value;}
}
public string ENG_HRS = "ENGINE HOURS";
private string c_ENG_HRS_var;
public string ENG_HRS_var
{
get { return c_ENG_HRS_var;} set { c_ENG_HRS_var = value;}
}
public string ENG_TYPE = "ENGINE TYPE";
private string c_ENG_TYPE_var;
public string ENG_TYPE_var
{
get { return c_ENG_TYPE_var;} set { c_ENG_TYPE_var = value;}
}
private string c_ENG_TYPE_name;
public string ENG_TYPE_name
{
get { return c_ENG_TYPE_name;} set { c_ENG_TYPE_name = value;}
}
public string TRANS_TYPE = "TRANSMISSION TYPE";
private string c_TRANS_TYPE_var;
public string TRANS_TYPE_var
{
get { return c_TRANS_TYPE_var;} set { c_TRANS_TYPE_var = value;}
}
private string c_TRANS_TYPE_name;
public string TRANS_TYPE_name
{
get { return c_TRANS_TYPE_name;} set { c_TRANS_TYPE_name = value;}
}
public string DIAG = "DIAGNOSTICS";
private string c_DIAG_var;
public string DIAG_var
{
get { return c_DIAG_var; } set { c_DIAG_var = value; }
}
}
It works now, but for better performance as far as memory management, aka. Garbage collection what's better?.
I've been reading on the class/struct thing, reference vs. value. I 'm leaning toward struct for performance and hopefully stability. I need the ability for each truck to have the ability to take and hold information. I could always figure away to pass the info to the monitor form
This below is what I've found:
You want your type to look and feel like a primitive type.
You create a lot of instances, use them briefly, and then drop them. For e.g., within a loop.
The instances you create are not passed around a lot.
You don't want to derive from other types or let others derive from your type.
You want others to operate on a copy of your data (basically pass by value semantics).
I'm I right to think to changing to a struct and if so what should the struct even look like? I hope this is enough detail.
One last question, is the class Engine complex enough to stay a class or can I safely change to a struct?
Thanks
|
|
|
|
|
From your summry, it sems you've read this[^] article.
If you read the section when not to use stucts you will see
"should ideally be below 16 bytes".
For that reason alone, with all those strings it's gonna be way above that, so stick with the class.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
I'd leave them as class es.
Worrying about performance differences between class and struct is generally a waste of effort; "performance" is not a reason to choose one over the other.
A truck is not a value, you don't perform operations with it.
|
|
|
|
|
If you are concerned about performance you shouldn't use strings for things such as IP addresses..
You can safely change it to a struct, but as you know it will pass by value, and it's big - so don't pass it.
Just change "class" to "struct" and you're done.
BUT, the struct vs class thing isn't likely to be the problem here (it occasionally pops up when dealing with several millions of instances of some type). I'd advice you to get a good profiler (such as ANTS from Red Gate) and look at what is really slowing it down.
|
|
|
|
|
1.
class without a doubt, it really is an object, not a value; rather big; needs passing around; etc etc.
As you have 20 odd string pairs in it, how will one more object make a difference?
(suggestion: make the feature strings static)
2.
your communication is using RS232C, which isn't really a fast interface. How can your code be in trouble performance-wise? How much is there to compute for one truck (250msec)?
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Sorry for wasting everbody's time. I'll do more research before asking anything. I thank everybody for there response.
L.
|
|
|
|
|
No problem.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
I am adding pages like this:
TabPage newPage = new TabPage();
newPage.Text = "Text"+tabControl1.TabPages.Count;
tabControl1.TabPages.Add(newPage);
RichTextBox richTextBox1 = new RichTextBox();
richTextBox1.Location = new Point(0, 0);
richTextBox1.Size = newPage.Size;
richTextBox1.Dock = DockStyle.Fill;
richTextBox1.Name = "RichTextBox" + tabControl1.TabPages.Count;
newPage.Controls.Add(richTextBox1);
Now i would like to cut something from richtextbox of selected tab..how to??
|
|
|
|
|
You could use the Find() method of tabControl1.SelectedTab.Controls, passing the name of the RichTextBox you want to find. That will return a Control object, so cast it to a RichTextBox and call Cut()
|
|
|
|
|
Can you show me in code plz...
|
|
|
|
|
Control foundControl = tabControl1.SelectedTab.Controls.Find("RichTextBox name goes here");
RichTextBox castControl = foundControl as RichTextBox;
if(castControl != null)
castControl.Cut();
You set the name of the RichTextBox when you create it, in your first code sample
|
|
|
|
|
Sen^or
Ola. Que tal con usted ahoraita???? Que bueno. Como yo usar uno pequino solucion los problemas que ocurrian en mi vida???
Gracias por que lo estay egualen la todo.
|
|
|
|
|
You will find here that most, if not all people are reluctant to just do code for you. People will give you hints and instruct you on classes and design help, but almost none will give you the code to do your job or homework.
|
|
|
|
|
I am askin for one line of code...for which my didn't work.. plz help! Do i have to use focus for getting richtexbox of selected tab??
|
|
|
|
|
My code won't work on its own. The name property of the RichTextBox is needed, and it's easily obtainable from your original code sample
|
|
|
|
|
RichTextBox richTextBox1 =new RichTextBox();
richTextBox1=tabControl1.SelectedTab.Controls[0] as RichTextBox;
That works fine! Thanks anyway!
|
|
|
|
|
You get a five from me for taking the time to work out alternative solutions
|
|
|
|
|
hi
i make a game and i want to publish it, but i dont want to anyone can know what game engine i use in it easyly!
my resource is .jpg image and ... and i dont want to anyone can grab those.
i want a wrapper that convert my game files and folders to single .EXE file that be runable without any footmark. so others can not understand what is behind it.
what software i must use for it?
|
|
|
|
|
I you've got the cash, it can be done - here[^] is one offering - starts at $6000 though.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Why dont you create a Setup for your game? I mean an installation wizard.
|
|
|
|
|
Hi Peoples,
I am using an application, of that i want to know where the mouse is clicked on that application ??
can u peoples help me how to do that?
|
|
|
|
|
Handling the MouseDown, MouseClick (and probably many other of the mouse-related) events of a form will provide the location (as X and Y co-ordinates) within the event args.
Select your form, look in thew properties panel for a little lightening-bolt-looking symbol and click it This will list all of the events available to you and if you then double-click the one yo want i will even provide a code-stub for you to use.
|
|
|
|
|
If you handle one of the Mosue events (MouseClick etc) you can use e.Location
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|