|
They're probably basing it on the relative "cost" of each. Throwing an exception can take a very long time - much longer than boxing or unboxing.
Still, if you want to get pedantic, you can say that a lot of boxing/unboxing will give a greater slow down than one exception, and you should only use exceptions in "exceptional circumstances" where it's likely the program won't be able to continue anyway.
Come to that, if you really want to optimise things, you should avoid using interfaces, iterators, properties, and a load of other C# features as well, since they're expensive at run time...
There are three kinds of people in the world - those who can count and those who can't...
|
|
|
|
|
molesworth wrote: if you really want to optimise things, you should avoid using interfaces, iterators, properties, and a load of other C#
Fixed that for you!
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Although C# is pretty fast if you use it carefully...
There are three kinds of people in the world - those who can count and those who can't...
|
|
|
|
|
molesworth wrote: C# is pretty fast
And getting faster - upto 9.8 m/s/s faster
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Just curious, where that you get that value? (this is not a "citation needed!", I just like benchmarks)
|
|
|
|
|
I think he just threw it up in the air (think about it )
There are three kinds of people in the world - those who can count and those who can't...
|
|
|
|
|
I would agree, thou it's a bit of a tricky one. Although both are costly, 'Throwing Exceptions' will benefit the application (i.e. errors will be handled and therefore must be an improvement). I think the problem with the question is the use of the word 'optimize' as that gives the impression of improving performance. I guess in this case it's meant to mean improving the application as a piece of software.
Just out of interest, what was the third option?
EDIT:
Oh, which should not be used... Well then surely that's an invalid question.
Am I right in saying that the Q&A is suggesting that you should use 'Frequent Boxing and Unboxing' to optimize a windows application?! Why the hell, in any situation, would adding more work optimise anything. The only thing that made 'Throwing Exceptions' valid is that it has benefits.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
"Which three of the following should not be applied to optimize a windows application"
What I get from this is: What will slow down an application.
Now there were 5 possible answers, I dont actually remember the rest but basically they say that only the Throwing exceptions one is correct and im saying that boxing/unboxing will also "not optimize an app".
Thanks for your thought guys, the voices in my head stopped for a second there.
|
|
|
|
|
|
You're not crazy. Unless you're misusing exceptions for general control flow (instead of exceptional control flow), (un)boxing is more likely to be a performance problem. Exceptions are not supposed to happen - so it doesn't matter that they're slow.
|
|
|
|
|
The application I am writing, the user has to right click on the file and tell the file to Run As and login with a admin account. Is there a way to tell if the user that is logged in running the program is a admin or not? This is in XP not vista.
|
|
|
|
|
Hi,
this is a snippet I once used, it shows "User" or "User, Administrator" IIRC:
List<string> roles=new List<string>();
try {
Thread.GetDomain().SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
WindowsPrincipal wp=new WindowsPrincipal(WindowsIdentity.GetCurrent());
foreach(object roleName in Enum.GetValues(typeof(WindowsBuiltInRole)))
if (wp.IsInRole((WindowsBuiltInRole)roleName)) roles.Add(roleName.ToString());
} catch (Exception exc) {
log(exc);
}
log("Windows role = "+string.Join(", ", roles.ToArray()));
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.
|
|
|
|
|
Hi,
I've added a setup project to my solution and added the project output from a windows App. The install worked fine.
I then changed 2 settings in my config file from User settings to Application settings. Rebuilt the projects and tried to re-install. The config file did not get updated in the installed version. I'm using vs2008.
I even tried removing the setup project and creating a new one. But, the old config was still installed! How is the Setup Project still referencing the old config file? I click on the project output in the setup project and select "Outputs". This gives me the directory to the config file. I've checked this and it does point to the correct version of the config file. So I'm confused as to why the config file isn't changing.
Any ideas?
Thanks.
|
|
|
|
|
Sorry for replying to my own post.
I've tried this again in anther solution. Just added a Win App and a setup project to the solution. I added some Application settings to the app.config file and installed. Then Changed the Application settings to User Settings and re-installed. The config did change on the second install so now I am really confused.
The only thing that I can see that I am doing differently in my main solution is Changing the Assembly Version number. Would this affect the Config File not being correctly installed when using the Setup Project?
|
|
|
|
|
Hi,
I know I'm not getting much input on this but I've just deleted the Setup project and added again but with a different Project name and this worked. This has got me over the problem short term but I'm worried what will happen when I need to upgrade my project.
Last attempt but has anyone got any ideas? I've tried changing the version number of the setup project and setting "RemovePreviousVersion" to true but everything I tried just didn't work.
|
|
|
|
|
If I change a static class variable in one application instance and I have multiple instantiated applications using the same dll will I be able to see that specific modification from one of my other applications? I'm thinking yes but I'd like to know for a fact. Any words of wisdom?
Thanx
|
|
|
|
|
No. Instance data as well as static data only exists inside a single process. In order to share data amongst applications, you must take special steps and use one of many available mechanisms, e.g. memory-mapped files.
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.
|
|
|
|
|
Can you maybe elaborate on these mechanisms?
|
|
|
|
|
There are lots of mechanisms; whatever your need may be, a few of them will fit well.
Search for "interprocess communication", and read the documentation, there is plenty of it.
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.
|
|
|
|
|
|
This isn't fully correct...
there is a method.. not for the feint of heart..
you can go into the .prj (or.sln) file and make a manual reference to the
location of the dll that you compile from the static class
(for each project that you want to reference that particular dll)
I've never done it (needed to do it) myself but I've heard about it...
come to think of it you can basically do this by add>existing project> your_dll.sln
then whenever you modify your_dll.sln it will be compiled into your other programs..
did I ramble.. sorry.
|
|
|
|
|
ely_bob wrote: whenever you modify your_dll.sln it will be compiled into your other programs..
you can add the same code to several processes, that does not magically make them share some data; unless the code you are sharing is taking care of interprocess communication, but then you don't need a DLL for that.
ely_bob wrote: did I ramble
a bit (if not a byte)
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.
|
|
|
|
|
Remoting the static instance is an option. Remoting offers out of the box support for singletons.
|
|
|
|
|
Hi
I’ve bean trying to create my own stile for the comboBox but something is going wrong.
The text box is drawing black. Does any one know how to fix this ???
Roy
|
|
|
|
|
Possibly it is reacting to your spelling and punctuation.
precious roy wrote: I’ve bean been trying to create my own stile style for the comboBox but something is going wrong.
The text box is drawing black. Does any one know how to fix this ??? ?
Without more information as to what your code is doing to make it draw black, I really can't say...
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|