|
All right:
- No, you can't access the L2 cache directly. Instead you make sure that your data structures exhibit locality of reference, both in space and time, so try not to use linked lists, or trees, or hash tables, etc. Use arraya.
- I meant what I said: write your code in the simplest, most obvious way possible. Then, and only then, when it's all working and tested, profile it. Find out where your major performance problems lay (if you have any major ones). Then start refactoring with using struct instead of class, creating temp variables, using unchecked or unsafe or both, etc.
- To do the previous part, make sure that you have proper unit tests set up beforehand. Comment changes you make for performance reasons, especially if they're not obvious.
Cheers, Julian
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
I try to flip metafile ,but I recive this kind of exception:
An unhandled exception of type 'System.NotImplementedException' occurred in system.drawing.dll
Additional information: Not implemented.
|
|
|
|
|
Hi there,
I really hope someone can help me with this one. Here's my problem:
I'm wrapping the RAS api in C#for the compact framework. Everything works fine except for one thing: setting and getting the RASDIALPARAMS structure for a certain entry.
Since the CF does not support enough Marshalling features, I have a byte array that represents the RASDIALPARAMS struct initialized as follws:
DIALPARAMS = new byte[1462];<br />
DIALPARAMS[0] = 0xB6;<br />
DIALPARAMS[1] = 5;<br />
Encoding.Unicode.GetBytes(Name, 0, Name.Length, DIALPARAMS, 4);
I've ued the same technique for other structs and have no problem at all. With this one though, the following API call always returns invalid parameter:
<br />
uint ret = RasGetEntryDialParams(null, re.DIALPARAMS, ref pw);<br />
What is really weird: When I use my struct with the RasDial function it seems to work: the function returns a valid connection handle and the ppc device starts sending AT commands over the serial line.
Has someone got an idea on what's wrong here?
Many thanks in advance,
G
"D'Oh!" (Homer J. Simpson)
|
|
|
|
|
|
Sorry maybe I wasn't clear enough on the fact that I'm using the Compact Framework (CF) on WinCE were there is no such thing as a ras book. Everything is stored in the registry and on WinCE it's all Unicode.
My approach works fine for all structs and API calls exept for the Set- and GetRasEntryDialParams...
G
|
|
|
|
|
|
Don't know if anyone is interested in readin this, but I found the problem myself.
I did not realize that C structs are aligned to be a multiple of 4 bytes (32 bits, of course).
That's why I have to use 1464 in stead of 1462 bytes for my array.
Pretty stupid isn't it!
Gino
"D'Oh!" (Homer J. Simpson)
|
|
|
|
|
Hi.
I have a datagrid on my form that has the datasource set to a datatable in a class in different project but same solution. When I change the data in the datatable, the datagrid is very long to get the changes (~2 seconds) which is not great. I use a bit complicated architechture, but it should not matter. Here's roughly what i do:
_____
ClassState:
DataTable MyData = new DataTable();
(Fill in dummy data)
_____
ClassForm:
MyGrid.DataSource = ClassState.MyData;
ClassEvents.MyGetData();
_____ -->
ClassEvents:
DataTable temp = MyWebService.GetData();
classState.MyData.BeginLoadData();
Foreach(datarow dr in temp)
{
classState.MyData.ImportRow(dr);
}
classState.MyData.EndLoadData();
//From here and until the datagrid is updated it takes ~2 seconds. WHY??
____________
I timed and logged every line in my code and found out that it is the datagrid that i slow on getting the updates (or the datatable that is slow sending update notifications). It has nothing to do with getting data from the webservice.
Is there some way to tell the datatable to send notifications NOW??
Or could it have something to do with the fact that ClassState, ClassForm and Class events each is in it's own project (but same solution)?
Or do you have any other ideas?
|
|
|
|
|
We can show the text with DrawString,but I cannot get width & height of the text,though I need them.
Can you help me?Thanks
Future belongs to C#!
|
|
|
|
|
use the Graphics.MeasureString method.
To those who didn't make it, we will remember you. To those who did is back. - Megan Forbes in Black FridayAnother Post by NnamdiOnyeyiri
|
|
|
|
|
|
Get it here[^], but remember, it can only be used in non-commercial apps. Get it quick, because rumors are that it may be gone soon.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
|
Help?
I modified some code from an MSDN sample to try to use the RijndaelManaged object to encrypt a byte array(an uploaded file from a browser) and stuff it into an image field in SQLServer. Seems like an easy task, right?
The files are definitley scrambled. Just can't seem to un-scramble 'em. I created an Encrypt and a Decrypt function, both of which accept a byte array and return a byte array. The key and IV are hard coded at this point.
I've been through the step of encrypting and decrypting at the same time, to see if the un-encrypted file makes it into the database....no love. It's hammered.
Somethin' ain't right. Here's the code for the functions:
<br />
public byte[] EncryptStream(byte[] input)<br />
{<br />
RijndaelManaged rijn = new RijndaelManaged(); <br />
byte[] encrypted; <br />
byte[] key = new byte[]{0x22,0xc0,0x6d,0xcb,0x23,0xa6,0x3,0x1b,0x5a,0x1d,0xd3,<br />
0x9f,0x85,0xd,0xc1,0x72,0xed,0xf4,0x54,0xe6,0xba,0x65,<br />
0xc,0x22,0x62,0xbe,0xf3,0xec,0x14,0x81,0xa8,0xa};
byte[] IV = new byte[]{0x43,0xb1,0x93,0xb,0x1a,0x87,0x52,0x62,0xfb,0x8,0xd,0xc0,<br />
0xca,0x40,0xc2,0xdb};
<br />
ICryptoTransform encryptor = rijn.CreateEncryptor(key, IV);<br />
<br />
MemoryStream msEncrypt = new MemoryStream();<br />
CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write);<br />
<br />
<br />
csEncrypt.Write(input, 0, input.Length);<br />
csEncrypt.FlushFinalBlock();<br />
<br />
encrypted = msEncrypt.ToArray(); <br />
<br />
return encrypted;<br />
<br />
}<br />
<br />
public byte[] DecryptStream(byte[] input)<br />
{<br />
RijndaelManaged rijn = new RijndaelManaged(); <br />
byte[] decrypted; <br />
byte[] key = new byte[]{0x22,0xc0,0x6d,0xcb,0x23,0xa6,0x3,0x1b,0x5a,0x1d,0xd3,<br />
0x9f,0x85,0xd,0xc1,0x72,0xed,0xf4,0x54,0xe6,0xba,0x65,<br />
0xc,0x22,0x62,0xbe,0xf3,0xec,0x14,0x81,0xa8,0xa};
byte[] IV = new byte[]{0x43,0xb1,0x93,0xb,0x1a,0x87,0x52,0x62,0xfb,0x8,0xd,0xc0,<br />
0xca,0x40,0xc2,0xdb};
<br />
<br />
<br />
ICryptoTransform decryptor = rijn.CreateDecryptor(key, IV);<br />
<br />
MemoryStream msDecrypt = new MemoryStream(input);<br />
CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read);<br />
<br />
decrypted = new byte[input.Length];<br />
<br />
csDecrypt.Read(decrypted, 0, decrypted.Length);<br />
<br />
return decrypted;<br />
}<br />
Thanks-
chlock
|
|
|
|
|
I'm just guessing here, one thing that comes to my mind now is the key and the initialization vector that may have some wrong values, as you've declared them as hardcoded arrays. Just to eliminate this doubt, try using the rijn.GenerateKey() and rijn.GenerateIV.
I hope that you have money because it’s necessary to be practical.
And I hope that at least once a year you put some money in front of you and say "you are mine" just to make clear who owns who. - Victor Hugo
|
|
|
|
|
OK-
I haven't taken the time to comb through the code and find what I was doing wrong. With all the arrays flying around, I suspect I just used the wrong variable somewhere.
The following code works. So it's there for anybody who wants a simple method for encrypting/decrypting byte arrays. It's hard to find examples that aren't written for the writing-an-encrypted-file-to-disk crowd.
Bear in mind that hard coding the key and IV theoretically leaves you open to some hacker reverse engineering your code and being able to easily decrypt your files. But my personal feeling on this matter is that it's infinitely more likely that a user will compromise security by leaving their password on a sticky note stuck to their monitor. And I'm not securing highly sensitive material anyway. If you have a need for greater security, use some other method for generating and keeping track of your keys and IV's.
<br />
public byte[] EncryptStream(byte[] input)<br />
{<br />
RijndaelManaged rijn = new RijndaelManaged(); <br />
byte[] encrypted; <br />
<br />
byte[] key = new byte[]{0x22,0xc0,0x6d,0xcb,0x23,0xa6,0x3,0x1b,0x5a,0x1d,0xd3,<br />
0x9f,0x85,0xd,0xc1,0x72,0xed,0xf4,0x54,0xe6,0xba,0x65,<br />
0xc,0x22,0x62,0xbe,0xf3,0xec,0x14,0x81,0xa8,0xa};
byte[] IV = new byte[]{0x43,0xb1,0x93,0xb,0x1a,0x87,0x52,0x62,0xfb,0x8,0xd,0xc0,<br />
0xca,0x40,0xc2,0xdb};
<br />
ICryptoTransform encryptor = rijn.CreateEncryptor(key, IV);<br />
<br />
MemoryStream msEncrypt = new MemoryStream();<br />
CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write);<br />
<br />
<br />
csEncrypt.Write(input, 0, input.Length);<br />
csEncrypt.FlushFinalBlock();<br />
csEncrypt.Close();<br />
<br />
encrypted = msEncrypt.ToArray(); <br />
<br />
return encrypted;<br />
<br />
}<br />
<br />
public byte[] DecryptStream(byte[] encrypted)<br />
{<br />
RijndaelManaged myRijndael = new RijndaelManaged(); <br />
byte[] fromEncrypt; <br />
byte[] key = new byte[]{0x22,0xc0,0x6d,0xcb,0x23,0xa6,0x3,0x1b,0x5a,0x1d,0xd3,<br />
0x9f,0x85,0xd,0xc1,0x72,0xed,0xf4,0x54,0xe6,0xba,0x65,<br />
0xc,0x22,0x62,0xbe,0xf3,0xec,0x14,0x81,0xa8,0xa};
byte[] IV = new byte[]{0x43,0xb1,0x93,0xb,0x1a,0x87,0x52,0x62,0xfb,0x8,0xd,0xc0,<br />
0xca,0x40,0xc2,0xdb};
<br />
<br />
<br />
ICryptoTransform decryptor = myRijndael.CreateDecryptor(key, IV);<br />
<br />
MemoryStream msDecrypt = new MemoryStream(encrypted);<br />
CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read);<br />
<br />
fromEncrypt = new byte[encrypted.Length];<br />
<br />
csDecrypt.Read(fromEncrypt, 0, fromEncrypt.Length);<br />
<br />
return fromEncrypt;<br />
}<br />
enjoy-
chlock
|
|
|
|
|
Hi,
I have a tool bar in my app, from which the user can drag components on to the a form. This works fine except that after dragging a control from the toolbar, once the mouse leaves the tool bar area the corresponding button remains in pressed state and will not become normal until the mouse is brought back on the tool bar. I want the button to become normal as soon as the mouse is release(on the form or elsewhere!)
Any ideas?
Thanks
|
|
|
|
|
I'll ask the obvious... Check if the button type is a toggle sytle.
-------------------------------
Joan
MomComputerGeek.com
|
|
|
|
|
This happens even with button style being set to either toggle or pushbutton
|
|
|
|
|
I have a C# Windows form app with its own installer... I'd like the installer to create several empty subfolders below the install dir that will hold data that will be created by the app... how can this be done...??
thanks,
vince
|
|
|
|
|
Why not just have the app check if the folder exists upon startup and create it if it does not exist? That way, users can delete the folders, and the application will not break.
|
|
|
|
|
thanks for the reply... as it turns out, that's exactly what I ended up doing
|
|
|
|
|
hello
i starting learning a c# and i am in my first step.
i find an exemple who talk about spliting a windows and i tryed to exucute but i acount a problem the sample don't work and i have many error .
i want to know the step to do to creat a project for this sample.
<br />
using System;<br />
using System.Drawing;<br />
using System.Windows.Forms;<br />
<br />
<br />
<br />
public class UnPanelUnSplitter : Form<br />
{<br />
private Splitter splitter1;<br />
private Panel panel1;<br />
<br />
<br />
public UnPanelUnSplitter()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
<br />
private void InitializeComponent()<br />
{<br />
this.splitter1 = new Splitter();<br />
this.panel1 = new Panel();<br />
this.SuspendLayout();<br />
this.splitter1.Dock = System.Windows.Forms.DockStyle.Left;<br />
this.panel1.BackColor = System.Drawing.Color.Yellow;<br />
this.panel1.Dock = System.Windows.Forms.DockStyle.Left;<br />
this.panel1.Resize += new EventHandler(PanelOnResize);<br />
this.panel1.Paint += new PaintEventHandler(PanelOnPaint);<br />
this.BackColor = System.Drawing.Color.Red;<br />
this.ClientSize = new System.Drawing.Size(319, 322);<br />
this.Controls.AddRange(new System.Windows.Forms.Control[] {<br />
this.splitter1,<br />
this.panel1});<br />
this.Text = "Un panel avec un splitter";<br />
this.ResumeLayout(false);<br />
this.Resize += new EventHandler(PanelOnResize);<br />
this.Paint += new PaintEventHandler(PanelOnPaint);<br />
<br />
}<br />
<br />
<br />
<br />
static void Main() <br />
{<br />
Application.Run(new UnPanelUnSplitter());<br />
}<br />
<br />
<br />
<br />
<br />
void PanelOnResize(object o, EventArgs e)<br />
{<br />
Control control = (Control)o;<br />
control.Invalidate(); <br />
}<br />
<br />
<br />
void PanelOnPaint(object o, PaintEventArgs args)<br />
{<br />
Control panel = (Control)o;<br />
Graphics grfx = args.Graphics;<br />
grfx.DrawLine(Pens.Black, 0, 0, panel.Width-1, panel.Height-1);<br />
grfx.DrawLine(Pens.Black, panel.Width-1, 0, 0, panel.Height-1);<br />
grfx.DrawEllipse(Pens.Black, 0, 0, panel.Width-1, panel.Height-1);<br />
}<br />
}<br />
|
|
|
|
|
hi !
i tried this little sample and it worked fine. (apart from the fakt that it doesn't look very pretty)
A)
start your editor
paste the code
save it as "split.cs"
compile at "VisualStudio .Net 2003 COMMAND PROMPT" with "csc split.cs"
run it: split.exe
-- or --
B)
make a new c# project. -> windows application
replace the code of Form1.cs with your code. run it.
if you have still errors, please post them.
|
|
|
|
|
>hello
>sorry,but it don't work and i guess that is from because i am newbies.
>when i select Form1.cs it appear a ressource but i don't see when i can put my code,and when i click on the form it send me to a code and when i put the code it don't work.
>please,can u explain me with detail how to add the code and when i find Form1.cs .
>thank u,and sorry for any distruption
--
there must be a "form1.cs" in your solution explorer (right sided). just right-click and select "view code"
now you see the whole code of this form (actually the whole code of the entire project/solution)
delete that code completely.
and paste your code instead.
now "form1.cs" is just your code.
thats it.
start the whole thing. it should work.
good luck.
andi
|
|
|
|
|