|
This is a late comment, but the Microsoft documentation states that you can get the VMR9Config and VMR9AplhaBitmap interfaces by calling IDVDGraphBuilder:GetDVDInterface()
IE:
hr = dvdGraph.GetDvdInterface(typeof(IVMRFilterConfig9).GUID, out comobj);
and
hr = dvdGraph.GetDvdInterface(typeof(IVMRMixerBitmap9).GUID, out comobj);
You do this before you call the RenderDVDAudioVideo and the graph understands that you want to use the VMR. Past that, you should be able to follow the VMR samples.
I think that the only thing that you really need is to get the MixerBitmap interface and then you can send an Alpha bitmap from a mem dc anytime that you want. I could be incorrect on that.
Myself, I am getting an hr = 1 on RenderDVDAudioVideo. Is strange, as I can manually build the graph I want.
MB
|
|
|
|
|
How much does Try... Catch blocks slow down your code?
I understand that if you have one it's nothing, but if you have multiple try... catches that are nested, how will efficiency and speed be effected?
If there is a significant decrease in efficiency and speed, what would be the best way to regain that lost efficiency without compromising integrity and catching those exceptions?
(Sorry if this post isn't directly related to C#, I'm well aware it should have gone in .NET framework, but I wasn't quite to sure if this could be a direct C# issue if at all and wasn't so concerned for a c++.net/CLI or VB.net answer)
|
|
|
|
|
EliottA wrote: How much does Try... Catch blocks slow down your code?
Not at all. They can actually be quicker than having to test everything to avoid Exceptions.
|
|
|
|
|
Everything I've read suggests that having try/catch blocks does not affect performance. The only way performance is affected is if you are throwing exceptions.
(And yes, this is a general .NET thing, not a C# specific one)
|
|
|
|
|
EliottA wrote: How much does Try... Catch blocks slow down your code?
I've never seen it slow down any of my apps.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Hi,
the try statement pushes some information to the execution stack; this info gets popped again when the try block closes without exceptions; or the stack gets searched for it when an exception occurs (that is the purpose of the info). So a try statement has a small cost associated with it.
Manual nesting of try blocks will have a limited depth, and typically only the inner one will be relevant; now there is no way around if you want to catch a possible exception at that level (e.g. because you want to continue with the next iteration of the inner loop).
And you can't easily nest try blocks programmatically (if would take run-time code generation to do that), unless you have a recursive method. Which is the way to go if you want to measure the try cost: write a recursive program containing a stopwatch and run it; then add a try-catch to the recursive method and measure it again. You probably will not see a significant difference, the recursion is much more costly than the try statement itself.
Here is some test code:
public override void Test(int arg) {
long rep=100000;
long n=1000;
Stopwatch sw=new Stopwatch();
sw.Start();
for (int i=0; i<rep; i++) sw.Stop();
log(sw.ElapsedMilliseconds.ToString());
Stopwatch sw2=new Stopwatch();
sw2.Start();
for (int i=0; i<rep; i++) sw2.Stop();
log(sw2.ElapsedMilliseconds.ToString());
}
long fact(long n) {
if (n<=1) return 1;
return n*fact(n-1);
}
long fact2(long n) {
try {
if (n<=1) return 1;
return n*fact2(n-1);
} catch (Exception) {
return 0;
}
}
modified on Wednesday, November 26, 2008 4:39 PM
|
|
|
|
|
Hi All!
I am trying to search for any URL inside files on my hard drive and these URL's could be anywhere inside the file, surrounded by letters/numbers etc and place each found URL into a listbox or string but it is proving to be very difficult. I was wondering if anybody might have any pointers/samps/links they could kindly share? Id appreciate any help I can get from anybody. Thanks for your time
Regards,
j.t.
P.S.
the code i have is as follows but something tells me i'm goin' about this the wrong way...:
private void SearchButton_Click(object sender, EventArgs e)
{
string fName = FileList.SelectItem.Text;
StreamReader testTxt = new StreamReader(fName);
string allRead = testTxt.ReadToEnd();
testTxt.Close();
string regMatch = "http://www." + <word> + ".com"/".net"/".org";
if (Regex.IsMatch(allRead, regMatch))
{
SearchQueryTextBox.Text = (regMatch + " was found.");
}
else
{
SearchQueryTextBox.Text = (regMatch + " could not be found.");
}
}</word>
j.t.
|
|
|
|
|
You don't cover https, or urls that were stored without the www or the http://, or with something else. You also assume all sites are American. But, if you clean up the regex, this is certainly the way to go about it.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Thanks I'm still a little stuck though, I don't know what to do next.
j.t.
|
|
|
|
|
Hi,
I have 2 databases, I´m using linq to duplicate entries from one to the other.
One table is an entry table with an identity column in the source database and I want to replicate to the other database.
The tables are exactly the same except for one column, the primary key, is an IDENTITY column.
I want to use the same class for the source/target table for code reuasability, but I´m unable to figure out how to fix it with the identiy column.
Is there a way to change this attribute runtime ?
[Column(Storage="_Nr", AutoSync=AutoSync.OnInsert, DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)]
I think that would solve my problem.
Thanks.
|
|
|
|
|
Hello all, (sorry if it is lay-man question)
here is my scenario:
1. Windows client in one machine, Remote object is hosted in IIS in different machine.
I need to pass context information (say, user identity) to remote object from client. I can achieve this from CallContext object but ThreadPool management of IIS sometimes not migrating the callcontext information in thread swapping scenario (from threadpool), so, the information is lost. (if have time read this article http://piers7.blogspot.com/2005/11/threadstatic-callcontext-and_02.html)
I decided to use HTTPContext object, which will be passed across different threads properly. I am planning to store the identity info to HTTPContext object at client and retrieve it from server.
a. In this scenario how can i make use of httpContext object?
b. is that at all possible or make sense to use HTTPContext in this scenario?
c. do we need to have only web client to make use of httpContext object?
(Am using HTTChannel for remote sinks)
Appreciate any inputs.
Thanks.
|
|
|
|
|
hai this is madhu...,
Please help me....
the below coding is getting path from App.config. The problem is..i gave path static. but i want that path is taking by default. Please help me.
XmlDocument doc = new XmlDocument();
doc.Load(System.Configuration.ConfigurationSettings.AppSettings["hardwareinfo"].ToString());
XmlNodeList bookList = doc.GetElementsByTagName("hardware");
foreach (XmlNode node in bookList)
{
XmlElement bookElement = (XmlElement)node;
txtOS.Text = bookElement.GetElementsByTagName("OperatingSystem")[0].InnerText;
txtProcessor.Text = bookElement.GetElementsByTagName("Processor")[0].InnerText;
txtMemory.Text = bookElement.GetElementsByTagName("Memory")[0].InnerText;
txtHardDisk.Text = bookElement.GetElementsByTagName("HardDisk")[0].InnerText;
}
---------- the app config---
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="hardwareinfo" value="E:\Madhu\Work\Old\SampXML\SampXML\hardwareinfo.xml"/>
</appSettings>
</configuration>
|
|
|
|
|
We have two types of assertion classes in .NET: Debug and Trace. I understand Debug assertions are only for development and are not shipped if built in release mode. How do you decide which one to use? I know if I want the assertion to fire during production then I should use Trace but what can help me decide this. I am also aware too many production assertions can hinder performance.
|
|
|
|
|
Actually, it's simple: The things you only want to see in debug mode should use Debug , the others Trace . If you use a library like log4net[^] then you can also differentiate between Debug, Info, Warning, Error and different output formats like file, e-mail, syslog etc., which is more suited for real production message logging.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi all, i didn't know which forum to post this on, so i hope this is the right one
(i know i wrote a lot of stuff here, if you should be to lazy to read all of this, i understand , but please read the last codeblock)
I am making a program in c# which detects usb devices and does stuff with the info i collect. I don't have a lot of experience with the usb stuff, so i have googled a lot of info together. Most of my code i wrote i translated from a c++ program. But my knowledge of c++ is minimum.
The problem is that i'm not able to translate a certain line of code to c#
in c++ i have something like this (i just copied a small piece but i think you get the idea)
typedef struct DEV_BROADCAST_DEVICEINTERFACE {
DWORD dbcc_size;
DWORD dbcc_devicetype;
DWORD dbcc_reserved;
GUID dbcc_classguid;
char dbcc_name[1];
}
struct DEV_BROADCAST_HDR {
DWORD dbch_size;
DWORD dbch_devicetype;
DWORD dbch_reserved;
};
PDEV_BROADCAST_HDR pHdr = (PDEV_BROADCAST_HDR)lParam;
PDEV_BROADCAST_DEVICEINTERFACE pDevInf;
pDevInf = (PDEV_BROADCAST_DEVICEINTERFACE)pHdr;
and in c# i have the following pieces of code
[StructLayout(LayoutKind.Sequential)]
public struct DEV_BROADCAST_HDR
{
public int dbcc_size;
public int dbcc_devicetype;
public int dbcc_reserved;
}
[StructLayout(LayoutKind.Sequential)]
public struct
DEV_BROADCAST_DEVICEINTERFACE
{
public int dbcc_size;
public int dbcc_devicetype;
public int dbcc_reserved;
public Guid dbcc_classguid;
public short dbcc_name;
}
DEV_BROADCAST_HDR pHDR = (DEV_BROADCAST_HDR)Marshal.PtrToStructure(msg.LParam, typeof(DEV_BROADCAST_HDR));
DEV_BROADCAST_DEVICEINTERFACE pDevInf;
now basicly i just want to translate THIS LINE from c++ to c#
pDevInf = (PDEV_BROADCAST_DEVICEINTERFACE)pHdr;
note: i have no idea what i'm doing, but i will be very happy if someone can give me a clue on how to translate this single line of code to c#
thanks in advance
|
|
|
|
|
I think this should work:
pDevInf = (PDEV_BROADCAST_DEVICEINTERFACE)Marshal.PtrToStructure(msg.LParam, typeof(PDEV_BROADCAST_DEVICEINTERFACE)); It seems to me that the second struct is merely part of the first one. It's probably just a way of "viewing" the data in memory.
|
|
|
|
|
thanks for the quick reply
this does indeed work, but when comparing the results from the c++ program with my c# program, a few parameters (like the dbcc size) have different values.. (maybe i just screwed up the rest of my code )
But to my knowledge i don't need these parameters, and i have the information i need from my usb devices, so i think my problems are solved (for now )
thanks again
|
|
|
|
|
Glad it worked.
I just noticed that you're defining dbcc_name in C# to be short , even though it's char in C++. This probably means that you may access memory that you shouldn't, and might cause you an access violation. I think the most accurate representation in C# would be sbyte .
|
|
|
|
|
|
Depends on whether you have to move the class/object around as an argument. If so, use a class.
Otherwise, it doesn't really matter technically, the two DateTimes will live equally happy on the heap or on the stack. But normally, structs are expected to be read-only data containers without behaviour (i.e. they should have no methods except c'tors, the 3 object-inherited methods, and operator-like methods like e.g. Compare ). What you have in mind sounds more like a service, so I think a class would be the better choice.
Regards
Thomas
www.thomas-weller.de
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Programmer - an organism that turns coffee into software.
|
|
|
|
|
if you consider using anything else but value types , then use a class. If not, you're free to use a struct
|
|
|
|
|
Jan Sommer wrote: if you consider using anything else but value types
Why should this make any difference? Can you explain that?
The struct/class may live on the stack/heap. In any case, it will contain its fields, so they will consequently live on the stack/heap as well. It is therefore absolutely irrelevant if they were values or refs.
Regards
Thomas
www.thomas-weller.de
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Programmer - an organism that turns coffee into software.
|
|
|
|
|
Boxing occurs if you use reference types in structs.. also, if he only plans to use value types it doesn't allocate as much memory then classes... see http://msdn.microsoft.com/en-us/library/ah19swz4(VS.71).aspx for details
|
|
|
|
|
Jan Sommer wrote: Boxing occurs if you use reference types in structs..
Ummm, what? No! This would mean that whole graphs of classes would be copied from the heap to the stack eventuallly when referenced by a struct .
See here: http://en.csharp-online.net/Classes,_Structs,_and_Objects—When_Boxing_Occurs[^]
Jan Sommer wrote: also, if he only plans to use value types it doesn't allocate as much memory then classes
This is also wrong as soon as there is more than one reference to the class/struct.
Regards
Thomas
www.thomas-weller.de
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Programmer - an organism that turns coffee into software.
|
|
|
|
|
Another minor difference: A struct is accessed by a pointer to its start in memory, but a class is accessed by a pointer to a pointer to its start. So if you're repeatedly accessing this object and you want the maximum efficiency, a struct will save one memory read per access.
As was pointed out earlier, a struct is less efficient to pass as a parameter because the whole object is pushed onto the stack. A class only has its reference (an address) put on the stack, so is faster to pass.
|
|
|
|