|
I'm trying to optimize some code that I've written and I've come across a style that I use ~20 or times that will be run ~100 or so times during the full execution of my code(a VSTO excel spreadsheet).
Here's the common syntax
If (complicated boolean statement)
{
form.attribute = true;
}
else
{
form.attribute = false;
}
I was wondering whether using something like this would make any difference
form.attribute = complicated boolean statement.
Could eliminating the if/else actually noticably speed up my code, or is this change so insignificant that I shoul concentrate on some of the other pieces of code to eliminate database calls and recomputation when it isn't necessary?
|
|
|
|
|
You can safely remove the if-else clause, but it won't result in a noticable performance increase.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
The difference in performance is so very small that it's more a matter of taste and style.
The second code is a bit more efficient, mainly because it doesn't contain a jump. If you only run the code a hundred times though, the difference in execution time is so small that it's not even possible to measure.
---
b { font-weight: normal; }
|
|
|
|
|
Hi,
my problem comes from the fact that I'm trying to make my progressbar progress while I'm scanning directory files.the awk thing is that my scan function is defined within my datalayer as a dll.I want my progress bar to follow the files processing. I first thought about threads but could'nt move on.probably got allergy for threads.can anybody help?
thanks in advance
|
|
|
|
|
If you have "access" to the source of the datalayer dll you could create some events. You can trap these events in your app then, like what the WebBrowser does with it's DocumentProgress (or something like that) event.
Ed
|
|
|
|
|
Your problem seems to be a perfect candidate for the BackgroundWroker thread control that's newly available in the .NET 2.0 framework.
Using this controll is rather pain free. It's literally a matter of a few click to get yourself set up with a background worker thread that is going ot perform the scan in background for you. The way you use this control is you have to provide three functions to handle three events. One is the actual worker function (this will be the function that scans the files). Then There is a function that will be called when the progress changes. And the last one is going to be a function that will be called when the thread ahs finished processing. So in the actual worker function you will need to call the ReportProgress function that will basically marshal your call and eventually fire the second event (the progress changed event) on the appropriate thread. It's that easy.
Feel free to google for the BackgroundWorkerThread samples online
Good luck
Mikk
----
www.muzikstor.com
|
|
|
|
|
Assume I send a ICMP packet that request timestamp, then I receive timestamp reply.
I can see type, code, identifier, sequence, originate time, receive time...
I can get a receive time.
and I Knew that I set a originate time.
how set a originate time value??
DateTime.Now??
DateTime.Now.ToFileTime()??
plz^^ Can you recommend me??^^
Nothing!! But gonzo!!
-- modified at 16:18 Thursday 20th April, 2006
|
|
|
|
|
hey hi, wanted to ask you guys that whenever I save some path in a column named "Picture", then it doesnt allow me to do so. how can I do it, or what type of column will i have to set it as?
regards,
noman
|
|
|
|
|
Standard question #2:
What error message do you get?
What data type have you chosen for the field?
---
b { font-weight: normal; }
|
|
|
|
|
hi, first of all, i wasn't sure in which forum i could place my article, so i put it in this one, because i'm working with C#...i hope someone could help me
the problem is that i simply can't create a Device in my app, it send me an error about "WindowsApplication1.Form1 is not an IntPtr..look i do something like this
Device dev = New Device(0, DeviceType.Default, this, CreateFlags.None, presentParams)
and the problem is in the third parameter ("this") , but then i don't know what to put in there...and by the way jeje...what is a IntPtr??
i'd really appreciate your help
thanks!
|
|
|
|
|
An IntPtr is a pointer to a memory location; it basically corresponds to a pointer in C++. It is 4 bytes on a 32-bit operating system, and 8 bytes on a 64-bit operating system.
What DirectX really requires is a C++ HWND object. The HWND is, guess what, a pointer to the handle of a window: DirectX is asking you want window to draw on, so it needs the window's handle.
A Windows Form (i.e. your Form class) is just a glorified window with a normal HWND under the covers. You can access the window handle (i.e. HWND) of your form using the form.Handle property.
Device dev = New Device(0, DeviceType.Default, this.Handle, CreateFlags.None, presentParams)
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Is Jesus the Jewish Messiah?
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
I have written an application using .NET CF that needs to write back files on a regular basis to a network share, ie \\server\data\foo.txt
How do I specify the username and password of an account that can access the share, so that the device can save to it?
Currently I have to open the share using Explorer on the PDA before I can save to it.
Thanks in advance...
Chris
|
|
|
|
|
Is there a way to import/export a MS Access report so that it can be modified in Crystal Reports XI?
Code Toad
|
|
|
|
|
Hey everybody.
I'm trying to print a document with a right-to-left language. I want to use the drawString() method, but it flips special signs like "." and "!" etc. just like in every other place in windows using this language (and left-to-right mode).
my question is, is there a right-to-left drawString()? or a way to turn this method into right-to-left?
my current solution is using drawString char-by-char using a method I wrote, but it seems like "Bad Programming" and very unefficient.
any ideas ???
Thanks!
|
|
|
|
|
Hi!
I need to flip or mirror a bitmap horizontally loading it from a file and saving the flipped one into another file.
I've seen some piece of code that is supposed to do this, but it uses "unsafe" code. Is there any way to do it without unsafe code?
Here's the code I found:
<br />
public static bool Invert(Bitmap b)<br />
{<br />
System.Drawing.Imaging.BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height),<br />
System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb);<br />
int stride = bmData.Stride;<br />
System.IntPtr Scan0 = bmData.Scan0;<br />
unsafe<br />
{<br />
byte * p = (byte *)(void *)Scan0;<br />
int nOffset = stride - b.Width*3;<br />
int nWidth = b.Width * 3;<br />
for(int y=0;y<b.Height;++y)<br />
{<br />
for(int x=0; x < nWidth; ++x )<br />
{<br />
p[0] = (byte)(255-p[0]);<br />
++p;<br />
}<br />
p += nOffset;<br />
}<br />
}<br />
b.UnlockBits(bmData);<br />
return true;<br />
}<br />
Thanx for any help!
|
|
|
|
|
If you surround your code with <pre> and </pre> then the post will retain your spacing. So looking at your formatted code, I end up with mismatch squirrly brackets:
sergestusxx wrote:
public static bool Invert(Bitmap b)
{
System.Drawing.Imaging.BitmapData bmData =
b.LockBits(new Rectangle(0, 0, b.Width, b.Height),
System.Drawing.Imaging.ImageLockMode.ReadWrite,
System.Drawing.Imaging.PixelFormat.Format24bppRgb);
int stride = bmData.Stride;
System.IntPtr Scan0 = bmData.Scan0;
unsafe
{
byte * p = (byte *)(void *)Scan0;
int nOffset = stride - b.Width*3;
int nWidth = b.Width * 3;
for(int y=0;y {
for(int x=0; x < nWidth; ++x )
{
p[0] = (byte)(255-p[0]);
++p;
}
p += nOffset;
}
}
b.UnlockBits(bmData);
return true;
}
}
Looking at the code in general (ignoring the obvious) the reason your unsafe is due to the use of the pointer. (something prefered to be avoided when possible)
Having said that, it looks like it is the only way that you can turn a bitmap into an array-addressable object for inversion.
This looks like a case where unsafe is not avoidable.
-- modified at 13:44 Thursday 20th April, 2006
|
|
|
|
|
You can use the RotateFlip method on the Bitmap class.
Josh
|
|
|
|
|
You can use a Matrix to draw a mirrored image. Look at the Graphics.Transform property.
---
b { font-weight: normal; }
|
|
|
|
|
It depends what you mean by "invert"; are you talking about inverting the colors of the bitmap? Or inverting the orientation of a bitmap?
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Is Jesus the Jewish Messiah?
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Hi,
Is there any way to register a COM dll at run-time, from the code, for example by a certain win32 API call?
Thanks for the help!
Shehzad
|
|
|
|
|
A good start would be to go on the correct forum: COM forum[^]
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
|
|
|
|
|
Hi,
Could someone please tell me what is the best way to late bind to COM dlls? I'm basically developing an application that loads specified dlls and then runs certain functions contained in those dlls. The problem is that I don't know the libraries to load until runtime, so I can't really use tlbimp. I know it is possible to use tlbimp at runtime (using TypeLibConverter) but this creates new names for the functions in the dll, so it may not be such a good idea...
Any help would be greatly appreciated, thanks!
Shehzad
|
|
|
|
|
Hi all,
I want to create a .txt file at runtime and fill it with the contents of a string array.
Could anyone help me
Thanks
John
|
|
|
|
|
Certainly:
Google is your friend[^]
Seeing as you've not specified a) what the string array contains or b) how you want this formatted in the text file - I can provide little help on the latter part.
|
|
|
|
|
Check out System.IO.File.WriteAllLines()
|
|
|
|