|
I find this code:
string sURL="http://localhost:8080/cercalia/img/dispositius_home.gif";
System.Net.WebClient RequestURI = new System.Net.WebClient();
System.IO.Stream objStream = RequestURI.OpenRead(sURL);
pictureBox1.Image = Bitmap.FromStream(objStream);
This Code Works OK.
Thank you for all.
|
|
|
|
|
After a long time I'm thinking to deal with programming again.
I want to write a math application(many graphics) with incredible many calculations in a little time so I must manipulate numbers(integer and real) as fast as possible.
I remember in "TURBO C" and old processors for fastest access(about two times faster) to integer numbers they should be declared as register and no more than two names otherwise the rest would be ignored.
In nowdays what about in "C#" and huge L2 cache memory of powerfull processors?
Has this capability to do with L2 cache?
I mean can I use L2 cache exclusively for frequently used variable names?
|
|
|
|
|
>I want to write a math program with incredible many calculations in a little time so I must manipulate numbers(integer and real) as fast as possible.
Use FORTRAN.
Seriously, if you want to write an app that does serious number crunching, maybe you'll save some development time by targeting a language that was designed and built to do serious number crunching. C# and .NET were designed to implement business applications. That's not to say they couldn't be used for math-type apps, but managed code doesn't lend itself very well to doing intensive work like that.
Also, if you want to write this app in C# (or any other language for that matter), I would just write the app in the simplest, most obvious way possible. Don't worry about performance right off the bat. Only when you have a working app do you worry about how quickly it runs: time it, profile it, and optimize it then. Trying to tune an application that isn't written yet is an exercise in building castles in the air.
Cheers, Julian
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
Dear Julian,
I don’t like FORTRAN and I don’t need the solutions to complex math problems that FORTRAN provides.
On the contrary I like C# and I need the speed of executing code and support in graphics mode that C# provides.
My calculations are plain operations but many as many are accesses to data that I have placed in memory. That’s why I want to know if I can access L2 cache memory directly placing there data I use more often.
|
|
|
|
|
Demokritos wrote:
want to know if I can access L2 cache memory directly placing there data I use more often
Perhaps the best is to write a little C lib to handle the crunching, and provide an interface via MC++.
leppie::AllocCPArticle("Zee blog");
|
|
|
|
|
Demokritos wrote:
Dear Julian,
I don’t like FORTRAN and I don’t need the solutions to complex math problems that FORTRAN provides.
On the contrary I like C# and I need the speed of executing code and support in graphics mode that C# provides.
My calculations are plain operations but many as many are accesses to data that I have placed in memory. That’s why I want to know if I can access L2 cache memory directly placing there data I use more often.
Graphics number crunching?
Why not use managed C++ with a directx view embedded. Id your doing 3D representations then it can handle it even better. Although, it make take to long to adapt writing to a buffer and not an actual coordinate. Either way as far as grphics go a directx port would be much faster than GDI+. But embedding directx inside a c# is like putting your car in neutral and trying to race.
If its speed you want go to c++, if its faster coding stay in c# and I would stay away from unsafe code. Its asking for trouble.
My thoughts and opinions do not in any way reflect what I just typed.
nick
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
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
|
|
|
|
|