A clever technique for the robust comparison of floating-point values -- reinterpreting the bits as sign-magnitude integers -- using purely verifiable, managed code.
Inspiration comes from Bruce Dawson (by way of Kim Gräsman) and Jeroen Frijters.
Some unit tests are included, but swim at your own risk, ok?
Strongly-typed collection class for System.Byte -- manages storage as a byte[] internally, to avoid both boxing and excess heap allocations. Use this class as a template for your own custom collection types.
A p/invoke wrapper for SetConsoleTextAttribute -- for writing colored text to the console.
The programming model for asynchronous I/O is an alien beast. You call BeginRead, specifying a callback function to be invoked asynchronously when the read operation completes (or the stream is closed). But you're not given the actual data -- for that, you have to call back into the stream's EndRead method, and then reestablish the async read by calling BeginRead, again. It's really quite a chore, because you have to have cached that Stream object somewhere... Uncle!
Doesn't .NET have a nice, tidy event model? Yes it does. Can't we just subscribe to receive the data as it comes in, without writing two pages of boilerplate code juggling streams, buffers, and IAsyncResult references? Yes we can.
Submitted for your approval: ASyncStreamPump, my attempt at a reusable solution for this problem... useful for large file copies, downloads, uploads -- can even be used to proxy a network connection, with just a few lines of client code!
Regular expressions created with RegexOptions.Compiled will leak, unless they're housed in a secondary AppDomain that can be unloaded -- you'll need this wrapper class, or something like it, to do that.
A similar technique can be used with System.CodeDom.Compiler types, or anything that uses Reflection.Emit under the hood.
It's not rocket science, but it's amazing how often folks get this wrong (also available in C#).
It's not rocket science, but it's amazing how often folks get this wrong (also available in unmanaged C++).
Use this helper function to "ping" a remote DCOM server, before calling CoCreateInstanceEx -- thus greatly mitigating the DCOM timeout problem (at least for the initial activation request).
Update -- Windows Server 2003 and Windows XP SP2 don't allow unauthenticated DCOM activation requests, by default (if at all). I'm removing support for bUnAuthenticated=true.
Encapsulating reusable dialogs as components (either in DLLs, or in COM objects) is a great idea -- much better than trying to reuse a .rc file -- but things get tricky if you like your dialogs modeless...
The ATL3 array template (CSimpleArray) is buggy and leaky -- don't use it (note: ATL7 finally repairs the bugs in CSimpleArray, and also offers a newer template, CAtlArray).
As seen in Attila (note: ATL7 offers similar functionality with their new CAtlList template).
The ATL3 string conversion macros are ugly (at best) or they pose terrible security holes (at worst) -- use this heap-based wrapper class instead (note: ATL7 offers a similar solution with its new CW2A et. al. classes).
Updated: Mon, 31 Dec 2007 03:12:00 GMT
Copyright © 2004-2007, Shawn A. Van Ness. All rights reserved. No warranties extended. Rocking or tipping this vending machine may result in serious injury or death.