|
Hello,
I am working on a GUI for XNA. I deliberately work on an older computer with a GeForce 7900 graphics card, so that I run into performance issues quicker than on a more up to date system. There is a small testing application that displays a GUI window with controls over an animated 3D scene. Here is a screenshot (sorry for the models, I'm not much of an artist):
http://img829.imageshack.us/i/screenshotja.jpg/[^]
Most work is done in two threads. One does the rendering, the other one is the UI thread. I have noticed, that both threads are always running on the same CPU core. For testing this is great. It forces me to do some profiling and refactoring when the CPU hits the ceiling. Under normal circumstances I would prefer to have the rendering thread on one core and the UI thread on the other. This way both thread would have lots of reserves left and should never get into any performance problems.
The problem is that I don't appear to have much influence on where the system schedules the threads. Am I overlooking something? Is there a way to make more efficient use of the CPU cores?
Edit: Sorry, I forgot: Pls gimme codez. Its urgentz.
"I just exchanged opinions with my boss. I went in with mine and came out with his." - me, 2011
--- I am endeavoring, Madam, to construct a mnemonic memory circuit using stone knives and bearskins - Mr. Spock 1935 and me 2011
modified on Tuesday, April 19, 2011 2:17 AM
|
|
|
|
|
The behavior of CPU load on multicore machines is very strange. When I run a Virtual machine with one virtual processor on a dual core host, and the virtual machines requires 100% of "its" core, Windows task manager does not report one core at 100% with the other at a low amount, but both cores with varying loads amounting in sum to just more than one fully used core.
Consequently, I would not worry about how to get the work load balanced between the cores, the operating system (same effect on Linux!) - or even the processor itself - is doing something already.
|
|
|
|
|
Well, both threads together run at 70% average of the one CPU they both run on. Sometimes the UI thread needed a little more and that CPU goes up to 100%. This also affects the rendering thread and the result is choppy rendering. I was able to optimize those peaks away and everything is fine now, but the point is that I want to prevent this as good as I can. Up to now I saw nothing that would make me hope that the system does anything to prevent that.
"I just exchanged opinions with my boss. I went in with mine and came out with his." - me, 2011
--- I am endeavoring, Madam, to construct a mnemonic memory circuit using stone knives and bearskins - Mr. Spock 1935 and me 2011
|
|
|
|
|
This[^] says don't do it, then gives you links to how to do it....but not for .NET
CDP1802 wrote: Edit: Sorry, I forgot: Pls gimme codez. Its urgentz.
But here[^] has some C# code using an interop.
Not going to yell about not Googling "setting thread affinity", since I never would have looked it up, otherwise. Gonna play around with it, now.
|
|
|
|
|
Thanks. You can't guess how much I googled and searched for threads and processes. But it's really easy as soon as you know the right name for what you are looking for.
"I just exchanged opinions with my boss. I went in with mine and came out with his." - me, 2011
--- I am endeavoring, Madam, to construct a mnemonic memory circuit using stone knives and bearskins - Mr. Spock 1935 and me 2011
|
|
|
|
|
Like asking someone how to spell a word and they say Look it up.
|
|
|
|
|
I would like to start playing around with the supposed great new language. I have Visual Studio 2008 and all the Visual Studio 2010 Express IDEs. I downloaded the F# development packages (InstallFSharp & InstallFSharpPowerPack.) It seems that the only thing I can do to use F# is to open some crappy console window. Is there any way for me to be able to set up regular WinForm & WebApp components with F# through one of my existing IDE's? What would be the point in me trying to help out Micro$oft's new language if the damn thing will only allow me a crappy console IDE? Why would I want to waste my time on this?
|
|
|
|
|
If you compare a C# winforms project with a console project you will see the main difference is the Program.cs file calls Application.Run with a new instance of the start up form. Also the project output type (in project properties) is set to Windows Application instead of Console Application.
You can do this in F# too. First change the project output type to Windows Application.
Then, you can create a form in code and send it to Application.Run:
open System.Windows.Forms
let formMain = new Form()
Application.Run(formMain)
I'm not sure if it's possible to use the designer to create/modify forms though.
[Edit] You will also need to add a reference to System.Windows.Forms of course! [/Edit]
[Edit2] Just found this article[^] [/Edit2]
Dave
Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.
Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
modified on Thursday, April 14, 2011 3:53 PM
|
|
|
|
|
swampwiz wrote: I would like to start playing around with the supposed great new language.
swampwiz wrote: Why would I want to waste my time on this?
I think you answered your own question.
|
|
|
|
|
I had a discussion at work today.
I made a Class that keeps a Private Dictionary(Of String, List(Of IMyInterface)) .
I have exposed some Methods that allow adding to the List(Of IMyInterface) . The managing of the Dictionary is handled in my Class .
Now to add or delete an item to or from a list, that belongs to a Key in the Dictionary I have made a Method that can be called like:
MyClass.AddToList("Key", New IMyInterfaceClass1)
MyClass.AddToList("Key", New IMyInterfaceClass2)
MyClass.DeleteFromList("Key", TypeOf(IMyInterfaceClass1))
MyClass.DeleteFromList("Key", TypeOf(IMyInterfaceClass2))
Now a co-worker said that a beginning programmer could not understand this(?) and that it should look like:
MyClass.AddToList(Of IMyInterfaceClass1)("Key")
MyClass.AddToList(Of IMyInterfaceClass2)("Key")
MyClass.DeleteFromList(Of IMyInterfaceClass1)("Key")
MyClass.DeleteFromList(Of IMyInterfaceClass2)("Key")
I can agree with him that his method looks pretty nice, but programming is not about beauty of code (not completely anyway). According to my co-worker my Class should be responsible for the creation of the Type that is given to the Generic Method . I do not think that creating Classes using Reflection is really best practice if you have other options, and I have never seen Microsoft Classes (or any Class ) that works like this. On top of that it becomes impossible to add a IMyInterfaceClass that requires parameters in its constructor.
Have I really not understood anything about programming or am I really so good that I am the only one who understands how to pass Classes as a parameter to a Function ?
It's an OO world.
|
|
|
|
|
Naerling wrote: Now a co-worker said that a beginning programmer
A truly beginning programmer understands nothing and will have trouble with everything.
Someone who is a bit more than a beginner, say two years of experience, is going to understand what they have been exposed to and will have difficulty with anything else. So if they have seen one idiom then the other will be the problematic one. It doesn't matter which one it is.
Naerling wrote: I do not think that creating Classes using Reflection
is really best practice if you have other options,
Correct. You use reflection because you must not because you can.
|
|
|
|
|
Exactly my thoughts... Besides, if a beginner is such a beginner that he can't pass a Class as a parameter I doubt that he can call a Generic Method
It's an OO world.
|
|
|
|
|
Assuming that I followed your naming convention in assuming that both IMyInterfaceClass1 and IMyInterfaceClass2 are expected to implement IMyInterface, you both are partially right. Your solution is superior on insertion, while your coworker's solution is superior on removal.
It is better to accept an instance of IMyInterfaceClass on insertion, because it does not tie your implementation to classes with default constructors. It is better to use a generic on removal because doing so lets you have the compiler enforce the requirement that IMyInterfaceClass1 and IMyInterfaceClass2 are implementations of IMyInterface, rather than relying on a run-time check.
|
|
|
|
|
That sounds good. Although the removing method checks if the given type is in the list and if it is it removes it. If it is not it simply does nothing. Although the generic would make it clear that you can only remove IMyInterfaceClasses, since those are the only ones you can add
My 5 for the suggestion.
It's an OO world.
|
|
|
|
|
Silently ignoring a call that passes an incompatible type is not a good idea. In 100 cases out of 100, calls like this indicate that the caller has made a typo: he couldn't have possibly added the item that he is trying to remove, so it's a logical error. As the result, whatever he meant to remove does not get removed, and it all happens silently. The piece of code that finds the item that has been left behind may be far away from the code containing the actual error. That's why I'd prefer a generic: it catches the typos at compile time, preventing potentially costly debugging sessions virtually for free.
|
|
|
|
|
dasblinkenlight wrote: In 100 cases out of 100, ...That's why I'd prefer a generic: it catches the typos at compile time,
preventing potentially costly debugging sessions virtually for free.
In 40 years of programming I haven't seen 100 errors associated with incorrect type usage.
Not even sure I have seen 10.
On the other hand I have seen more than 10 and probably as many as 50 logic errors in code in the past 4 years that either were explicit security problems or had the potential for that.
And thousands of other types of logic errors.
And quite few very obtuse errors some that required hours (at least) to debug involving reflection.
So generics are amusing but they are far from vital.
|
|
|
|
|
The other posts have already given a good answer to your question, so all I'd like to add is:
When first reading the code, your version of the code is clearer (to me). It's very clear that you are adding what's in the parameter.
In your co-workers example, I'd think AddToList does something with adding "Key" to a list, and I wouldn't readily be able to figure out what the generic is doing there in that function.
Same with the deletion: your code makes it clear *what* you are deleting, whereas the alternative leaves it unclear to me what is actually being deleted. Though it is less confusing with the delete than with the add.
So, for first time readability, I'd use your code too.
Combining that with the previous comments: either leave your code as it is, or use your code for adding and the co-workers code for removing (so you get the compile-time type checks).
Best Regards,
MicroVirus
|
|
|
|
|
Generics is about knowing the type at compile-time - you only know the type at execution time.
There are two ways of fixing this:
*
Make the generic code call the non-generic code instead. That's easy, but you won't have any of the benefits of generics.
*
Use reflection to call the generic code from the non-generic code. That's fiddly and won't perform as well, but you can deprecate the non-generic code and eventually remove it.
|
|
|
|
|
I don't follow the code your coworkers wrote. I understand your code though, it makes perfect sense.
If you do any MVVM programming, you have pass not only classes, but delegates (which is even more confusing) to methods in order to do asynchronous programming. Your co worker is all kinds of crazy.
I didn't get any requirements for the signature
|
|
|
|
|
ToddHileHoffer wrote: Your co worker is all kinds of crazy.
I was just going to bed. After reading this I will sleep very well
I do not think delegates are even allowed in our company... To confusing, as you mentioned
It's an OO world.
|
|
|
|
|
I read the question and all the responses. All were at a high level. I am a beginning programmer, 1 1/2 quarters to go for my degree.
The first implementation makes the most sense to me. Up until now I had never seen parameters sent separatly i.e f()() they have always been f( , ).
As I said, I am beginning and may be all wet in the way I read the code, but will use this post to try some new ideas.
Thanks, this was interesting.
dj
|
|
|
|
|
My example may seem a bit weird to you. Try declaring a List(Of String). You probably have done that sometime? Well, surprise, you can actually say List(Of String)(10), where 10 is the capacity of the list, which is the same syntax as my example.
Perhaps it would be clearer in C#, where it would be typed List<string>(10);. You can now clearly see there is a difference between the first and second 'parameters'
The first specifies a Type (for example String or Integer, which will be used elsewhere in the Class or Method) while the second are actually parameters you pass to the method, usually of the Type you just specified.
I think when you try it out you will find it very easy
It's an OO world.
|
|
|
|
|
Thank you, that clears up the syntax for me. I will have to find a required progam that I have to write to try it out on.
DJ
|
|
|
|
|
Actually a List(Of T) can be used in almost any program. You could look in the System.Collections.Generic Namespace to find more types of Generic Collections. Or you could write your own Generic Class. I always just write some stupid program that does absolutely nothing, but where I use some techniques I am not yet familiar with to practice. Good luck!
It's an OO world.
|
|
|
|
|
This seems to be the best forum for my questions, so here goes.
My company's website is being redesigned, and I would like to add more security regarding some of the user information we store. My questions are about best practices and which of the .Net Framework's methods are preferable.
Some data, like contact information, will be encrypted. This allows the data to be stored securely and be converted back into plaintext for display in various contexts. Is there a particular method in System.Security.Cryptography that is considered better than the rest?
I'm not sure whether passwords will be encrypted or hashed. I believe hashing is faster, but if a user forgets his password it cannot be looked up and will have to be changed. Also, we have business rules saying that a user must change his password every 30 days and cannot change it to any password used in the last 6 months: whatever method I implement must be compatible with these rules. Any suggestions?
|
|
|
|