|
IIRC, a volatile read/write creates a memory barrier, which forces all updates to the variable to happen before it is read or written into.
Locking the instance should be more of a performance hit, I guess, because one thread accessing any field will prevent any other thread from accessing any other field. The best thing is to profile and find it out, I guess.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Volatile will produce better performance, but it will behave differently. Adding a lock on the entire class will ensure that operations changing multiple fields will be consistent. Go with the lock unless you can show that you need a better performing option, and then you might want to look at a lockless operation, but coding those can be very tricky.
I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
|
|
|
|
|
Hello,
Is there a way of making a specific cell in a DataGrid as ReadOnly? I really need the help on this one.
Thank you
|
|
|
|
|
I already gave you an answer the first time you had this question. If this wasn't detailed enough than tell me what exactly you didn't understand.
|
|
|
|
|
Hello People,
I have a problem with the ImageList class in C#.
I add the image list in my form with the resource editor.
When I edit the collection and add a new image (bmp), the comiler compiles correctly but I have a crash in the execution when the code looks like this:
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
which is a line generated automatically.
Why this happens?
Thanks for the explanations
There is no spoon.
|
|
|
|
|
Hello,
I have a web service that returns a custom object, which has a property of type Guid . Somehow it seems that the Guid is not marshalled, because on the generated proxy (and in the XML) it never appears.
Any ideas? I thought about converting it to a string and putting it into another property, but I don't like that idea. Something else? some XML-related attribute?
Thanks!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Hello everyone.
I'm trying to build an application that searches for specified few bytes and prints out their location (offset) within binary file.
Now, I use "while" loop to go through every offset location to check where the bytes are, and on large files it's naturally slow.
Is there any built in method in .NET that can do that for me? I've been using FileStream class and it looks like it doesn't have such functionality.
Thanks everyone in advance!
|
|
|
|
|
You could use some string search func.
One way to fasten up your while loop is simply to check only for the first letter of the search string and if it's correct you'll check if the rest is
correct to.
This will fasten up your program A LOT!
And this I think you can't get faster with .Net...
This isn't hard to do in assembler, there it would get really fast...
Niklas Ulvinge aka IDK
|
|
|
|
|
Heh... Didn't even think of the posibility to check for the first letter.
Thanks much!
|
|
|
|
|
Happy to help
Niklas Ulvinge aka IDK
|
|
|
|
|
Additionally, for even more speed, you might try this out as a little COM automation funtion written in C++. It is such an easy one to write, that it would be worth a try.
I did a routine to calculate hashes for files this way and it was significantly faster. I don't know how much of that was due to the IO speed vs. calculation speed. I would suspect since you wouldn't be doing too much calculation, you wouldn't get as much performance increase, but probably enough to justify doing it this way.
Matt Gerrans
|
|
|
|
|
Hi,
Is there a way to perform a foreach loop on all the elements of an enumeration?
Thanks
|
|
|
|
|
you can do:
enum MyEnum
{
One,
Two,
Three
}
foreach (MyEnum me in Enum.GetValues(typeof(MyEnum))
Console.WriteLine(me.ToString());
|
|
|
|
|
Hello, I have created a Solution in C#.Net which consists of 3 separate
projects and numerous dependency files which are organized into
directories such as databases, images, usage files, etc. When the
program runs, it searchs for the various files it needs in each of
these directories. I am now working on creating an Installer project
for this Solution so that it may be simply installed on a user's
computer. I have added all of the necessary files to this
Installer/Set-up project and I see that it is possible to specify where
these files are installed onto a new computer but changing the "Folder"
property for each dependency to either "Application Folder", "User's
Desktop", or "User's Programs Menu". I would like to know how I can
specify that a dependency file be installed to a custom location such
as "Application Folder/images/". There must be some simple way to do
this that I am just missing. Any help would be much appreciated.
Thank you.
|
|
|
|
|
I am a newbie in C#. I tried to build a COM+ application by creating an interface like this:
public interface ITest
{
int sum(int x, int y);
}
then I created a class which inherit from ServicedComponent and this interface.
After that I complied and deployed it by using regsvcs. Everything seemed to be fine, but when I checked my COM+ from COM Admin, I not only saw the inferface but also the class methods.
It doesn't seems right because normally, only the interface's method should be there.
What did I do wrong here?
Thanks,
Tommy.
|
|
|
|
|
i need before to show my application create some object that is i need to set
// declarations
...
// this panel is showed in the form
private System.Windows.Forms.Panel panel1;
// this is just a needed-in-memory panel
private Panel myobject = new Panel();
...
private void InitializeComponent(){
this.panel1 = new System.Windows.Forms.Panel();
}
// now i have
private Any_Inithialize_Function(){
myobject = panel1;
}
if i do it in Main, onLoad, onPaint funtion (as Any_Inithialize_Function) i get memory error becouse panel1 is not yet created.
|
|
|
|
|
Assigning it right after InitializeComponent (in the Form's constructor) should work fine.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
if you mean write that line inside InitializeComponent it is deleted when i run the debug.
So it doesn't work.
|
|
|
|
|
I think he meant you should put your call right after the call to InitializeComponent inside the constructor.
|
|
|
|
|
I tried using the toolbar of VS.NET. And found that, it does not show the alpha region of the icons perfectly. I have tried using maximum color depth in the imagelist that was associated with the toolbar, and also tried using PNG images.
Nither of my approaches succeded
Is there any way to show the icons perfectly ??
thanks in advance.
|
|
|
|
|
are your png real 32bit files?
Sometime (it is a visual studio bug) it doesn't work, you have to delete all these image from the imagelist and reload them all in the same time.
Other bug become if you use not good png images. That is you have to make much attention at antialising your image when you draw it in your graphic program, i advice you to don't use much antialising.
Make me to know.
|
|
|
|
|
I am using 32bit PNGs. and also tried reloading the images but that did not work
|
|
|
|
|
so try to redraw these images using not strong antialising
|
|
|
|
|
|
I have a dum guestion... how do i declare an array of clases, an array in wich every element is a class i tried
class SomeClass
{
public int x;
public int y;
};
SomeClass[] a=new SomeClass[5];
everything goes ok.
when i run the prorgam and i try smth like :
a[3]=4; the program throws an exception.. pls help me..
|
|
|
|