Channel 9 - Discussions by PhrostBytehttp://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.pngChannel 9 - Discussions by PhrostBytehttp://channel9.msdn.com/Niners/PhrostByte/Discussions
Channel 9 keeps you up to date with the latest news and behind the scenes info from Microsoft that developers love to keep up with. From LINQ to SilverLight – Watch videos and hear about all the cool technologies coming and the people behind them.http://channel9.msdn.com/Niners/PhrostByte/Discussions
enTue, 31 Mar 2015 18:41:37 GMTTue, 31 Mar 2015 18:41:37 GMTRev9000Tech Off - C# 3.0: What I WantThe point was to *not* do these checks, but have .NET check and throw the exception for you. C# and .NET are geared toward quickly producing quality code and this could only help that - while I (grudgingly) check all my public methods I'm sure there are
a lot of coders out there who just assume things will never be null.

Chances are you don't need a custom message, and if you do, don't mark it non-nullable and do the checks yourself. It's a win-win idea.]]>http://channel9.msdn.com/Forums/TechOff/92949-C-30-What-I-Want/01103b34078b4eaa8f109dea01273e3a#01103b34078b4eaa8f109dea01273e3a
Mon, 01 Aug 2005 08:40:15 GMThttp://channel9.msdn.com/Forums/TechOff/92949-C-30-What-I-Want/01103b34078b4eaa8f109dea01273e3a#01103b34078b4eaa8f109dea01273e3aCory Nelson9http://channel9.msdn.com/Niners/PhrostByte/Discussions/RSSTech Off - C# 3.0: What I WantOne thing I really wished was in C# 2.0 way to specify a method argument as "non-nullable". Not having to manually check arguments for null would be a big plus in reducing and simplifying code.]]>http://channel9.msdn.com/Forums/TechOff/92949-C-30-What-I-Want/92949#92949
Mon, 01 Aug 2005 01:55:59 GMThttp://channel9.msdn.com/Forums/TechOff/92949-C-30-What-I-Want/92949#92949Cory Nelson9http://channel9.msdn.com/Niners/PhrostByte/Discussions/RSSTech Off - Who should learn unmanaged code?Learn C++. It takes a while to get there but once you start using a lot of the STL and templating you'll begin to miss it in C#. That said, C# is also an excellent language to learn. They just serve different areas.]]>http://channel9.msdn.com/Forums/TechOff/62690-Who-should-learn-unmanaged-code/80ec86186f834744a1789dea011e7adf#80ec86186f834744a1789dea011e7adf
Mon, 02 May 2005 19:28:24 GMThttp://channel9.msdn.com/Forums/TechOff/62690-Who-should-learn-unmanaged-code/80ec86186f834744a1789dea011e7adf#80ec86186f834744a1789dea011e7adfCory Nelson28http://channel9.msdn.com/Niners/PhrostByte/Discussions/RSSTech Off - Best line of code everI've seen people do a good deal of weird stuff, two of my favorites:

int i; i^=i; // optimization, makes i = 0, but faster.

char str[32];
strcpy(str, "foo");
strcat(str, "\0"); // set null terminator
]]>http://channel9.msdn.com/Forums/TechOff/29732-Best-line-of-code-ever/1efd354aef934544a68e9dea01165adc#1efd354aef934544a68e9dea01165adc
Thu, 02 Dec 2004 19:01:42 GMThttp://channel9.msdn.com/Forums/TechOff/29732-Best-line-of-code-ever/1efd354aef934544a68e9dea01165adc#1efd354aef934544a68e9dea01165adcCory Nelson16http://channel9.msdn.com/Niners/PhrostByte/Discussions/RSSTech Off - Should I make namespace std global?I usually do a "using namespace std" in source files (unless they are really small) and std::* in header files. It doesn't compile anything extra, just makes your life easier. The only way it can be bad is if you have custom classes with the same names
as the STL classes, in which case you will have to fully use std::* to declare one.
]]>http://channel9.msdn.com/Forums/TechOff/26983-Should-I-make-namespace-std-global/b018f05ba297484f88c29dea0115f91e#b018f05ba297484f88c29dea0115f91e
Fri, 05 Nov 2004 12:05:16 GMThttp://channel9.msdn.com/Forums/TechOff/26983-Should-I-make-namespace-std-global/b018f05ba297484f88c29dea0115f91e#b018f05ba297484f88c29dea0115f91eCory Nelson3http://channel9.msdn.com/Niners/PhrostByte/Discussions/RSSTech Off - .NET Gurus: Pinning a delegate for P/InvokeDeclare your function pointer as typedef void (*FuncPtr)(int i);

Rossj wrote:

PhrostByte wrote:Probably not, but the exception is still being thrown Anyone have a solution?

I wrote a simple bit of code to replicate this and it works, or rather I can replicate either of the two problems you mentioned. Without the GCHandle a NPE is thrown in the dllimport'ed function that calls the delegate from C (after it has actually done the
callback), and with the handle I get ArgumentException thrown about non-blittable types.

]]>http://channel9.msdn.com/Forums/TechOff/26851-NET-Gurus-Pinning-a-delegate-for-PInvoke/6e0f552f45a24f9c87389dea0115f787#6e0f552f45a24f9c87389dea0115f787
Fri, 05 Nov 2004 09:41:28 GMThttp://channel9.msdn.com/Forums/TechOff/26851-NET-Gurus-Pinning-a-delegate-for-PInvoke/6e0f552f45a24f9c87389dea0115f787#6e0f552f45a24f9c87389dea0115f787Cory Nelson17http://channel9.msdn.com/Niners/PhrostByte/Discussions/RSSTech Off - .NET Gurus: Pinning a delegate for P/InvokeProbably not, but the exception is still being thrown Anyone have a solution?

Rossj wrote:

PhrostByte wrote:Am I not able to use marshaling in a delegate? It compiles fine.

I am not sure that the MarshalAs is necessary. I'm just on my way home, if no-one else answers before then I'll look it up later.

]]>http://channel9.msdn.com/Forums/TechOff/26851-NET-Gurus-Pinning-a-delegate-for-PInvoke/e411de1633024f08b0e99dea0115f71d#e411de1633024f08b0e99dea0115f71d
Thu, 04 Nov 2004 23:06:31 GMThttp://channel9.msdn.com/Forums/TechOff/26851-NET-Gurus-Pinning-a-delegate-for-PInvoke/e411de1633024f08b0e99dea0115f71d#e411de1633024f08b0e99dea0115f71dCory Nelson17http://channel9.msdn.com/Niners/PhrostByte/Discussions/RSSTech Off - .NET Gurus: Pinning a delegate for P/InvokeAm I not able to use marshaling in a delegate? It compiles fine.

PhrostByte wrote:That is good advice if you are passing a delegate through one function. In my case the library is storing it.
I am doing:
setdelegate(d); // p/invoked, stores the function pointer
somefunc() // p/invoked, can call function pointer.
the delegate can be moved before or during somefunc()'s execution.

Do you mean moved (in memory) or changed (to point to a different method) ?

in memory.]]>http://channel9.msdn.com/Forums/TechOff/26851-NET-Gurus-Pinning-a-delegate-for-PInvoke/36b4d9bc0174413c925a9dea0115f5f9#36b4d9bc0174413c925a9dea0115f5f9
Thu, 04 Nov 2004 15:33:48 GMThttp://channel9.msdn.com/Forums/TechOff/26851-NET-Gurus-Pinning-a-delegate-for-PInvoke/36b4d9bc0174413c925a9dea0115f5f9#36b4d9bc0174413c925a9dea0115f5f9Cory Nelson17http://channel9.msdn.com/Niners/PhrostByte/Discussions/RSSTech Off - .NET Gurus: Pinning a delegate for P/InvokeThat is good advice if you are passing a delegate through one function. In my case the library is storing it.

Finally, a word on pinning. I often see applications that aggressively pin managed objects or managed delegates that have been passed to unmanaged code. In many cases, the explicit pin is unnecessary. It arises because the developer has confused the requirement
of tracking an object instance via a handle with the requirement of keeping the bytes of that object at a fixed location in memory.

...The PInvoke layer is hooked into the CLR’s stack crawling mechanism for GC reporting. So it can defer all overhead related to pinning unless a GC actually occurs while the PInvoke call is in progress. Applications that explicitly pin buffers around
PInvoke calls are often doing so unnecessarily.

]]>http://channel9.msdn.com/Forums/TechOff/26851-NET-Gurus-Pinning-a-delegate-for-PInvoke/5b9acbe238cc49ce9c729dea0115f5a5#5b9acbe238cc49ce9c729dea0115f5a5
Thu, 04 Nov 2004 15:17:17 GMThttp://channel9.msdn.com/Forums/TechOff/26851-NET-Gurus-Pinning-a-delegate-for-PInvoke/5b9acbe238cc49ce9c729dea0115f5a5#5b9acbe238cc49ce9c729dea0115f5a5Cory Nelson17http://channel9.msdn.com/Niners/PhrostByte/Discussions/RSSTech Off - .NET Gurus: Pinning a delegate for P/InvokeI'm attempting to P/Invoke a C library. It requires me to pass a delegate which the library will store for later use.

Because I do not use this delegate later in managed code it gets collected. Easy enough to stop, but pinning it in one memory location is another story. Is this possible?]]>http://channel9.msdn.com/Forums/TechOff/26851-NET-Gurus-Pinning-a-delegate-for-PInvoke/26851#26851
Thu, 04 Nov 2004 14:49:57 GMThttp://channel9.msdn.com/Forums/TechOff/26851-NET-Gurus-Pinning-a-delegate-for-PInvoke/26851#26851Cory Nelson17http://channel9.msdn.com/Niners/PhrostByte/Discussions/RSSTech Off - PHP 5 V ASP.Net (2)I use PHP for small one page hacks (which iirc is what PHP was made for). ASP.NET is much more organized, faster, and has a ton of backing. I refuse to use PHP for large projects.]]>http://channel9.msdn.com/Forums/TechOff/13331-PHP-5-V-ASPNet-2/5c87876545f94df081a09dea011212e5#5c87876545f94df081a09dea011212e5
Sun, 25 Jul 2004 05:46:30 GMThttp://channel9.msdn.com/Forums/TechOff/13331-PHP-5-V-ASPNet-2/5c87876545f94df081a09dea011212e5#5c87876545f94df081a09dea011212e5Cory Nelson16http://channel9.msdn.com/Niners/PhrostByte/Discussions/RSSTech Off - Jumping out of a heavily-nested loop not by using goto statement?Goto is only evil if used incorrectly. I have no problem using it to break out of a nested loop. Actually it's the only place I would use it..]]>http://channel9.msdn.com/Forums/TechOff/14014-Jumping-out-of-a-heavily-nested-loop-not-by-using-goto-statement/ab4fe14fe1db4def8a209dea01127396#ab4fe14fe1db4def8a209dea01127396
Sun, 25 Jul 2004 05:40:41 GMThttp://channel9.msdn.com/Forums/TechOff/14014-Jumping-out-of-a-heavily-nested-loop-not-by-using-goto-statement/ab4fe14fe1db4def8a209dea01127396#ab4fe14fe1db4def8a209dea01127396Cory Nelson59http://channel9.msdn.com/Niners/PhrostByte/Discussions/RSSTech Off - Memory manager problem?I'm sorry but regardless of how often or not a function is used, realloc() going over 600 times slower on Windows *is* horribly wrong. There is no excuse for slow code.

Thanks for the link though, I'll try that on the heap code.

edit: didn't mean to come off as hostile there. inefficiency in code is a pet peeve - I bug friends about things they write if they could be even 5% faster ]]>http://channel9.msdn.com/Forums/TechOff/12813-Memory-manager-problem/548c1e04571c403bbc899dea0111f2e2#548c1e04571c403bbc899dea0111f2e2
Wed, 14 Jul 2004 15:19:55 GMThttp://channel9.msdn.com/Forums/TechOff/12813-Memory-manager-problem/548c1e04571c403bbc899dea0111f2e2#548c1e04571c403bbc899dea0111f2e2Cory Nelson11http://channel9.msdn.com/Niners/PhrostByte/Discussions/RSSTech Off - Memory manager problem?Case #1:
That sample prog I gave did nothing but call realloc in a loop 640 times, so it is definately in realloc. Havn't changed any memory settings, and it is on the same PC with nothing unneeded running in the background. The times are from the program, and I don't
need it to be any more accurate as there is a massive noticable difference. I also compiled the same source with GCC in Windows (ala MinGW) and it ran even slower.

Case #2:
libxml2. This stemmed out of a recent convo in their mailing list where dumping large xml documents would take *much* longer on windows. After some investigation we found it was growing a buffer by 16KiB up to 10MiB. As soon as it was made to double the
current size instead of increasing it by a 16KiB the speed skyrocketed to be the same as it was on Linux.]]>http://channel9.msdn.com/Forums/TechOff/12813-Memory-manager-problem/1b1585276c4f4802b1fc9dea0111f30d#1b1585276c4f4802b1fc9dea0111f30d
Wed, 14 Jul 2004 15:10:45 GMThttp://channel9.msdn.com/Forums/TechOff/12813-Memory-manager-problem/1b1585276c4f4802b1fc9dea0111f30d#1b1585276c4f4802b1fc9dea0111f30dCory Nelson11http://channel9.msdn.com/Niners/PhrostByte/Discussions/RSSTech Off - Memory manager problem?good point.

under windows: it's compiled with full optimizations in non-managed mode using vs.net 2003. it happens with vs6 also.

See this source: http://dev.int64.org/memory.c
It runs in 8sec on winxp, and 0.013sec in linux. Even with my 1.5GiB of ram I thought maybe it wasn't able to expand the memory each time but I made it use a fixed 10MiB heap it and performs just as bad. Any gurus care to comment?]]>http://channel9.msdn.com/Forums/TechOff/12813-Memory-manager-problem/12813#12813
Tue, 13 Jul 2004 16:07:18 GMThttp://channel9.msdn.com/Forums/TechOff/12813-Memory-manager-problem/12813#12813Cory Nelson11http://channel9.msdn.com/Niners/PhrostByte/Discussions/RSS