|
SK Genius wrote: when you pass a string it's a whole new object.
Now that deserves a kick. A string parameter is not a new object, in fact it is a pointer (they like to call it a reference), just as it is in C/C++/Java. However it points to an immutable object, something the compiler will not allow you to modify, only replace.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Indeed, right you are. Glad too see I'm earning my Kicks.
I know that (almost) everything is passed by reference so you get the actual string but anybody who modifies or replaces it is then pointing to a new object, leaving the old one intact until GC will eventually devour its soul, right?
My current favourite quote is: Punch them in the face, see what happens!
-SK Genius
|
|
|
|
|
yes, that method is thread-safe: its results only depend on input parameters, and both string and char are immutable, so there is nothing that can disturb the method; also the method is not changing the outside world, so it isn't disturbing anything itself.
As soon as you start referring to other data, such as class members, things may change though.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
As you aren't operating on a member variable in this example, and you have a nice self contained method where you have immutable data, this is perfectly thread safe. In other words, there is no chance that another thread can change the value of xml or item and affect the outcome.
Suppose that you changed it so that xml was a member property of type XMLElement, and you passed item in - then you could have a none thread-safe method because you could affect XMLElement before you actually performed the operation on the XML.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Not if you change the string with unsafe code.
Otherwise the result will of course be correct for the (old) value of the xml parameter, but not necessarily for "something else" (I mean, if you passed in this.Xml or something like that, the result (when it is returned) may have nothing to do with the current value of that field)
|
|
|
|
|
Some articles say that if you pass variables to your method that are not immutable or reference variable this may make the method not Thread Safe.
Does any one has more details about this point if it is correct or wrong and why?
|
|
|
|
|
What exactly do you mean?
|
|
|
|
|
Hey
My program recieves a byte array containing a jpg. I am using Image.FromStream and then viewing the image on a picturebox. Image.FromStream is quite slow so is there any other way I could view the jpg?
Thanks
|
|
|
|
|
I don't believe there is another way. Apart from loading it from the disk (which really, opens the file then reads it from the stream)
There shouldn't really be any reason for it to go particularly slowly, unless it's a very large image. Could it be possible that something else is causing the lack of swiftness?
My current favourite quote is: Punch them in the face, see what happens!
-SK Genius
|
|
|
|
|
The problem is im recieving 16 video streams and each is 25fps. Thats 400fps and Image.FromStream is taking 3-4 ms per frame. Its just to slow.
|
|
|
|
|
So you're trying to play video in a picture box? You may want to check some articles on video playback with DirectX.
My current favourite quote is: Punch them in the face, see what happens!
-SK Genius
|
|
|
|
|
No there not videos. Its a frame from a IP camera along with other information and is sent from a server.
|
|
|
|
|
Either way, trying to render pictures so fast is beyond the capabilities and intended use of GDI+ (which is what is being used to draw your pictures)
The best you can do is call SuspendLayout on your picture boxes so that they don't redraw as soon as you've changed the picture and then ResumeLayout and Invalidate once you have updated all of your picture boxes. Reducing the number of redraws that are done, but even then I can't see it being very fantastic.
Also, if your showing lots of different pictures one after the other at a reasonably quick pace, I'd say that was video.
My current favourite quote is: Punch them in the face, see what happens!
-SK Genius
|
|
|
|
|
Ok thanx for the help. So if showing pictures at a quick pace is actually just a video surely I can use DirectX or DirectShow to play the "Video"? Or wont this be quick enough to do what I want? If not I will just have to reduce the frame rate.
Thanks
|
|
|
|
|
I am co-operating in the development of a data management system. I have written a seriously complicated component of the program with we are still debugging.
Now, I am going to use NUnit to automatize a number of tests. All said, but now, for debugging purposes, I will need to run a number of tests on the component. I have chosen really specific data to use for the testing and put those data in a folder of XML files. The structure of the XML files follows the structure of the database the data could be in, but I did this for 2 reasons: Due to a network problem, I can't connect to the test database, and I wanted to exclude "data noise" to really pinpoint my tests.
And now the question: how to I make NHibernate use my folder of xml files as a datasource instead of the test database?
|
|
|
|
|
c:\Program Files\Microsoft SQL Server\90\SDK\Assemblies\Microsoft.Sqlserver.connectioninfo.dll
how do i get an object for connectioninfo
so as to use the methods and properties of connectioninfo class
Pls guide me
thanks in advance
|
|
|
|
|
Does this[^] article help?
/ravi
|
|
|
|
|
Here I would like to know how to do a carriage return in C #, the equivalent of \ r \ n
public void initest(string par, int val)
{
TxFrame = par + val;
TxFrame += "\r\n";
m_ComPort.Write(TxFrame);
}
|
|
|
|
|
In general, you would use Environment.NewLine (say you are writing to a file and want to achieve the newline). In this specific instance, it looks like you are writing to a COM port so this isn't the case; what you have don here is correct.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
modified on Wednesday, June 2, 2010 7:59 AM
|
|
|
|
|
No offense, but I think that's a bad idea in this case - he appears to be using a COM port, and writing something platform dependent to it does not seem like a good idea to me.
|
|
|
|
|
Ah - I hadn't noticed the COM port usage there. You're right that this doesn't make sense in this case.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
\r\n works in C# (meaning that it produces a carriage return and a newline), what's the problem?
|
|
|
|
|
public void initest(string par==D, int val==1)
{
TxFrame = par + val;
TxFrame += "\r\n";
// the problem is the result of TxFrame is "D1\r\n"
m_ComPort.Write(TxFrame);
}
thanks
|
|
|
|
|
Ok, well then what do you want the result to be?
Or do you mean that you see "\r\n" in the debugger and thought that it meant backslash r backslash n?
|
|
|
|
|
yes I see him in the debug and I want it to be a carriage return
|
|
|
|