|
My app has to render a bitmap by scanning a FP measurement array, using a lookup table type process. In the old C++/MFC app that does more or less the same thing, the rendering runs very noticably faster using the same camera and image size, on the same PC.
In C#, I was using the SetPixel command, but this is still as slow as the infamous GDI SetPixel call. Getting a pointer to the bitmap data in an 'unsafe' code block speeds up the process by a factor of about 2.5, but its still slow.
So my questions are these.
1) Will calling an unmanaged C++ DLL function (derived from my old app) execute faster than the C# code? I'm thinking about DLL load overhead and similar.
2) Is it possible to embed C++ code directly in the C# project? My books and VS help seem to hint at this, but I have yet to find an explicit answer.
Thanks for any ideas.
Stewart DIBBS
|
|
|
|
|
sjdevo3gsr wrote: 1) Will calling an unmanaged C++ DLL function (derived from my old app) execute faster than the C# code? I'm thinking about DLL load overhead and similar.
Yes, in this case. Native pointer math is always faster for bitmaps, all other things being equal. If you're doing a lot of memory access and you're sure your not going to overrun any buffers or anything, unmanaged code can be blazingly faster for bitmap work. You may also have easier access to BitBlt and similar functions, which could save you a lot of math.
sjdevo3gsr wrote: 2) Is it possible to embed C++ code directly in the C# project? My books and VS help seem to hint at this, but I have yet to find an explicit answer.
You can put managed C++ classes in your C# project/solution. They're still managed, though. That may not necessarily be bad.
You can also but "unsafe" C# code inline in your C# files. That will allow you to use pointers. It's not going to be as fast as native Win32 C code, but it'll allow pointer math, which could save you time over ordinary C# code in this case.
|
|
|
|
|
From doing experiments with encryption (Blowfish) in both C# and mixed mode C/C++. The native code performs about 4 times faster (12MB/s vs 50MB/s throughput).
Use MC++ to mixed a little managed code with native code. There are ways to embed it, but it's a difficult process (not suggested). Have a look at the link below if you are interested.
http://blogs.msdn.com/junfeng/archive/2006/05/20/599434.aspx[^]
|
|
|
|
|
sjdevo3gsr wrote: Getting a pointer to the bitmap data in an 'unsafe' code block speeds up the process by a factor of about 2.5, but its still slow.
Have you rechecked if you really used the whole potential of this method? My measurements when I once met this problem where that the difference was factor 5 or more...
|
|
|
|
|
That was my reaction too. Using direct access to the memory area should be much faster than that. I would expect a factor ten at least.
---
b { font-weight: normal; }
|
|
|
|
|
hi,
does any one have an idea about how to show the Gird Lines in the whole DataGridView (VS2005) client area even the binded data list is empty?
Thanks a lot!!
Alan
Alan Shen
MCAD for .NET Version
^~^~^~^~^~^~^~^~^~^~^
Great idea is the beginging of success!
|
|
|
|
|
|
I currently have the following RegEx expression that requires the input of 5 alpha numeric characters. I am looking for help on how to modify this to allow 5 or 6 alpha characters. Also, How could this be modified to allow from 1 to 6 alpha characters.
[a-zA-Z0-9]{5}$
|
|
|
|
|
How about ^[a-zA-Z]{5,6}$ for 5 or 6 alpha characters and ^[a-zA-Z]{1,6}$ for 1 to 6.
|
|
|
|
|
Thanks.
BTW, where would be a good source to learn more about the RegEx format styles?
Also, What does the ^ and the $ mean in this expression.
Thanks
|
|
|
|
|
^ means start of line, $ means end of line. IF you did not put them, the [a-zA-Z0-9]{5} expression would validate any alphanumeric of 5 characters or more as OK in your input, while ^[a-zA-Z0-9]{5}$ validates alphanumric strings of exactly 5 characters.
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
|
|
|
|
|
|
Hello,
I whant to get a list of directorys like "E:" ... for all active USB and Floppy devices on my PC.
Thanks for your help,
Martin
|
|
|
|
|
Hi,
Im trying to remove a whole table from an xml file if the date is a month old or older.
This is the code i produced so far:
<code>using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Xml;
using System.IO;
using System.Xml.Xsl;
using System.Xml.Schema;
using System.IO.Compression;
namespace RemoveRows
{
class Program
{
static void Main(string[] args)
{
try
{
DataSet xmlFile = new DataSet();
xmlFile.ReadXml("xmlFile.xml");
foreach (DataRow dateRow in xmlFile.Tables[0].Rows)
{
string Date = dateRow["Date"].ToString();
DataRow[] tempXmlFileRows = xmlFile.Tables[0].Select("Date = " + Date);
DateTime dateNow = DateTime.Now;
DateTime dateOld =
string dateFormat = @"yyyy/MM/Dd";
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.Read();
}
}
}
</code>
And this is how the xmlFile looks like:
<root>
<test>
<Id> 1 </Id>
<Date> 20060604 </Date>
<Time> 1200 </Time>
</test>
</root>
The first 4 digits are presenting the year, the next 2 digits the month and the last 2 the day.
Can somebody help me with this please?
Thanks in advance!
-- modified at 14:38 Thursday 8th June, 2006
|
|
|
|
|
You're on the right track. You've loaded the data and you're iterating suitably. What you need now is to find the date to cut off at, and start removing records.
To find the day that was 30 days before today, try this:
<br />
DateTime dtOld = DateTime.Now.Date.Subtract(new TimeSpan(30, 0, 0, 0));<br />
Unfortunately, and for good reason, there's no easy constructor for TimeSpan to put in the month value and go. You could find it iterativel, something like this:
<br />
DateTime dtOld = DateTime.Now.Date;<br />
while (dtOld.AddMonths(1).Date > DateTime.Now.Date)<br />
dtOld = dtOld.Subtract(new TimeSpan(1, 0, 0, 0));<br />
dtOld will contain one month before today when that's running.
Next, you need an int value, because the <Date /> value stored in your XML is really just an int. Use this:
<br />
int intOld = dtOld.ToString("yyyyMMdd");<br />
Now, as you iterate through your set, compare each value to that value. If the int is less than that number, get rid of the data element.
HTH, ask more if you need more help.
|
|
|
|
|
Hi Stephan Samuel,
Thank you for your reply!
Im getting an error coz of this line:
int intOld = dtOld.ToString("yyyyMMdd");
It says:
Cannot implicitly convert type 'string' to 'int'.
And ehm it should not only remove the tag '<Date></Date>', but the whole table which contains the outdated row. This is kinda tricky for me.
Thank you very much!
|
|
|
|
|
Oh, yeah... this'll work better:
<br />
int intOld = Int32.Parse(dtOld.ToString("yyyyMMdd"));<br />
Removing elements from a DataSet is pretty easy:
<br />
DataSet dsMyData;<br />
<br />
<br />
...<br />
<br />
dsMyData.Tables.Remove("MyTableName");<br />
dsMyData.Tables.RemoveAt(0);<br />
<br />
DataRow dtMyRow = dsMyData.Tables["MyOtherTable"].Rows[0];<br />
<br />
dsMyData.Tables["MyOtherTable"].Rows.Remove(dtMyRow);<br />
dsMyData.Tables["MyOtherTable"].Rows.RemoveAt(0);<br />
<br />
dsMyData.AcceptChanges();<br />
<br />
dsMyData.WriteXml("c:\myfile.xml");<br />
There are other issues with deleting data from a DataSet, but you may get lucky and avoid the bulk of them. It's worth a try, and ask if you're getting a particular error you can't get through.
Stephan
|
|
|
|
|
Hi Stephan,
Thanks again for your reply.
Im getting a really strange error about 'Table test does not belong to this DataSet.' from the console.
I googled up this error, but no information what tells me how to deal with this error.
This is the code i have produced so far (with help from you):
static void Main(string[] args)
{
try
{
DataSet xmlFile = new DataSet();
xmlFile.ReadXml("test.xml");
foreach (DataRow dateRow in xmlFile.Tables[0].Rows)
{
string Date = dateRow["Date"].ToString();
//DataRow[] tempXmlFileRows = xmlFile.Tables[0].Select("Date = " + Date);
//DateTime dateNow = DateTime.Now;
DateTime dateOld = DateTime.Now.Date.Subtract(new TimeSpan(30, 0, 0, 0));
int intOld = Int32.Parse(dateOld.ToString("yyyyMMdd"));
DateTime dtOld = DateTime.Now.Date;
while (dateOld.AddMonths(1).Date > DateTime.Now.Date)
{
dateOld = dateOld.Subtract(new TimeSpan(1, 0, 0, 0));
if( tempXmlFileRows.Length != 0)
xmlFile.Tables.Remove("test");
xmlFile.AcceptChanges();
}
}
xmlFile.WriteXml("test.xml");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.Read();
}
I cant use the DataRow[] array, coz if i do it says:
Cannot find table 0. In the console.
Thanks again!
|
|
|
|
|
Unfortunately (for you), I can't write your program for you. I recommend getting a book on C# programming that includes a few chapters on DataSets and XML, and learning from that.
The errors your getting tell you exactly what's wrong. The tables you're trying to reference aren't in your DataSet. You need to point to the tables that you want to delete by their names or indices.
Somehow or other, and I'll leave it for you to figure out how, you're going to have to inspect the DataSet schema that's created from ReadXml() on your XML listing. Here's a hint: if you're using VS.NET, run your app in the debugger and pay attention to the Autos, Locals, and Command windows. They'll give you a look into the DataSet, and you'll have an idea of what to delete.
|
|
|
|
|
Hi Stephan,
Thank you for your reply.
The error did exactly tell me whats wrong, but the tables im trying to reference are in my dataset.
<root>
<test>
<id> </id>
<date> </date>
</test>
</root>
So i tried deleting the table test. That is a table right?
|
|
|
|
|
I'm new to C# (using 2003 .NET) and I was trying to create my first user control. Inside the User Control I have a toolbar which I would like to dock on the left. When I do so, the images inside my toolbar do not show, but the text does. I inserted the images by creating an imageList, which I reference in my toolbar and index on each of the buttons. I can see the image on the design view, but they never show when I run. I can choose to dock the toolbar on top, or on the bottom and then both images and text show. I would appreciate any ideas.
|
|
|
|
|
I'm not 100% sure, but I recall this might be a known bug. Try search the MSDN for details.
|
|
|
|
|
Using VS2005 and winforms. Have a TabControl with five TabPages. One page consists of labels and textboxes only. My users want the ability to print this TabPage. Not familiar with printing. Any easy way of doing this? thanks, gary
|
|
|
|
|
You could either write your own paint routine, or you can do the equivelant of a print screen by copying bits of the screen to a bitmap through API.
This is some VB code that I used in one of my other applications:
Public Function WindowCapture(ByVal form As Form) As Bitmap<br />
' Get this form's Graphics object.<br />
Dim me_gr As Graphics = form.CreateGraphics<br />
<br />
' Make a Bitmap to hold the image.<br />
Dim bm As New Bitmap(form.Width, form.Height, me_gr)<br />
Dim bm_gr As Graphics = me_gr.FromImage(bm)<br />
Dim bm_hdc As IntPtr = bm_gr.GetHdc<br />
<br />
' Get the form's hDC. We must do this after <br />
' creating the new Bitmap, which uses me_gr.<br />
Dim me_hdc As IntPtr = win32api.GetWindowDC(form.Handle)<br />
<br />
' BitBlt the form's image onto the Bitmap.<br />
win32api.BitBlt(bm_hdc, 0, 0, form.Width, form.Height, _<br />
me_hdc, 0, 0, win32api.SRCCOPY)<br />
bm_gr.ReleaseHdc(bm_hdc)<br />
<br />
' Return the result.<br />
Return bm<br />
End Function<br />
All calls to the win32api class are API calls or constants that can be found in the program APIViewer
Regards,
1tg46
Check out 3D Game Development with Dark Basic Professional [^]programming.
|
|
|
|
|
Hello,
I started an appl. for a touchscreen, where I designed a alphanumeric input pad.
When I now Click the Button for "a" I have to use the string.Insert Method to get the "a" in my text.
It would be much faster, if its possible to force this Event directly in the TextBox.
Thanks for your time,
Martin
|
|
|
|