Jump to content
Xtreme .Net Talk

IngisKahn

Avatar/Signature
  • Posts

    436
  • Joined

  • Last visited

Everything posted by IngisKahn

  1. Along those lines, would you be better served by a BinaryReader?
  2. Take a look at the MSIL for each version.
  3. Ya, but I'd suggest to stay away from Marshal wherever possible.
  4. Hehe. There is none. Embrace .NET! You can have VB access C# dlls, you can even have VB and C# in the same assembly.
  5. That's odd, I can modify the summary of all the files you mentioned except html. As for accessing this data in .NET, you'll have to use platform invoke, but that's OK since ADS isn't portable anyway.
  6. Who said otherwise? Then I must be in the Twilight Zone. Every Win2k and XP system I've used has summary info for every NTFS file.
  7. Man, I guess Damp and Iceplug don't use NTFS (shame on you :p ). Every file has hidden data stored with it in NTFS...even whole files.
  8. Sure: byte[] floatBytes = new byte[4]; float val; // assign values unsafe // remember to enable unsafe mode in the build options { fixed (byte* pfloatBytes = floatBytes) // all managed types must be fixed to use a pointer val = *(float*)pfloatBytes; }
  9. Are you sure you need MDI then?
  10. You should start then by downloading the latest SDK.
  11. The difference is so minimal that it can be ignored. Usually I try to follow P&P to the T, but since VS puts it outside by default I usually just end up leaving it there.
  12. It was added to Patterns and Practices since it directly relates the classes to the current namespace. (not that you'll often have multiple namespaces in the same file)
  13. If the control receives focus then you can use the LostFocus event.
  14. OK, how about we test it out? Here's the test app: namespace TestIt { using System; using System.Diagnostics; using System.Text.RegularExpressions; class Program { static void Main() { string test; int iterations = 10000; Stopwatch stopWatch = new Stopwatch(); while ((test = Console.ReadLine()) != "") { int iterator = iterations; stopWatch.Start(); while (iterator-- != 0) SplitWithStruct(test); stopWatch.Stop(); Console.WriteLine(stopWatch.ElapsedTicks); iterator = iterations; stopWatch.Reset(); stopWatch.Start(); while (iterator-- != 0) SplitWithRegex(test); stopWatch.Stop(); Console.WriteLine(stopWatch.ElapsedTicks); stopWatch.Reset(); } } static Regex regex = new Regex(@"\D"); static string SplitWithRegex(string text) { return regex.Replace(text, ""); } struct SplitString { public string Text; public int Number; } static SplitString SplitWithStruct(string text) { int firstNumericChar = text.Length; char[] chars = text.ToCharArray(); while (Char.IsNumber(chars[--firstNumericChar]) && (firstNumericChar > 0)); SplitString result; result.Number = int.Parse(text.Substring(firstNumericChar + 1)); result.Text = text.Substring(0, firstNumericChar); return result; } } } With minimal input (1 char and 1 digit) Regex is ~4.5 times faster. As input size doubles the Struct method run time nearly doubles, but Regex time increases at a much slower rate. Why? There's two reasons. One is that regex is highly optimized. For the second reason let's look at the MSIL: .method private hidebysig static string SplitWithRegex(string text) cil managed { // Code size 17 (0x11) .maxstack 8 IL_0000: ldsfld class [system]System.Text.RegularExpressions.Regex ConsoleApplication1.Program::regex IL_0005: ldarg.0 IL_0006: ldstr "" IL_000b: callvirt instance string [system]System.Text.RegularExpressions.Regex::Replace(string, string) IL_0010: ret } // end of method Program::SplitWithRegex .method private hidebysig static valuetype ConsoleApplication1.Program/SplitString SplitWithStruct(string text) cil managed { // Code size 70 (0x46) .maxstack 4 .locals init (int32 V_0, char[] V_1, valuetype ConsoleApplication1.Program/SplitString V_2) IL_0000: ldarg.0 IL_0001: callvirt instance int32 [mscorlib]System.String::get_Length() IL_0006: stloc.0 IL_0007: ldarg.0 IL_0008: callvirt instance char[] [mscorlib]System.String::ToCharArray() IL_000d: stloc.1 IL_000e: ldloc.1 IL_000f: ldloc.0 IL_0010: ldc.i4.1 IL_0011: sub IL_0012: dup IL_0013: stloc.0 IL_0014: ldelem.u2 IL_0015: call bool [mscorlib]System.Char::IsNumber(char) IL_001a: brfalse.s IL_0020 IL_001c: ldloc.0 IL_001d: ldc.i4.0 IL_001e: bgt.s IL_000e IL_0020: ldloca.s V_2 IL_0022: ldarg.0 IL_0023: ldloc.0 IL_0024: ldc.i4.1 IL_0025: add IL_0026: callvirt instance string [mscorlib]System.String::Substring(int32) IL_002b: call int32 [mscorlib]System.Int32::Parse(string) IL_0030: stfld int32 ConsoleApplication1.Program/SplitString::Number IL_0035: ldloca.s V_2 IL_0037: ldarg.0 IL_0038: ldc.i4.0 IL_0039: ldloc.0 IL_003a: callvirt instance string [mscorlib]System.String::Substring(int32, int32) IL_003f: stfld string ConsoleApplication1.Program/SplitString::Text IL_0044: ldloc.2 IL_0045: ret } // end of method Program::SplitWithStruct See all those calvirts? They add overhead that Regex doesn't have. So it appears that Regex is much much faster. Could you write a faster function? Maybe, but it would be very difficult and the gains would be minimal. BTW, I'm not a fan of Regex myself. The Regex filter strings are nearly impossible to read by the uninitiated.
  15. !(pLayer is ICompositeLayer) :)
  16. Be kinda silly if it didn't work.
  17. It might be a good idea to just use DrawString instead.
  18. All MDI applications behave this way. Your only option is to un-maximize the child form when you want to open another one.
  19. Thread queue. There are many cases where multiple threads should be used. In fact, nearly all UI apps should have the UI on a seperate thread. But a small chat bot won't see any benefits using multiple threads to handle multiple requests. Even if this was a huge chat server, threads wouldn't help unless you're running on a multi-proc system. But that's not what decrypt was asking about anyway.
  20. Please, let's not patronize now. I'm saying that a simple bot app doesn't need to be over engineered. When targeting single processor systems multiple threads should only be used in blocking situations such as disk IO/GUI. Context switching is very expensive. Unless he's expecting thousands of requests per second then there shouldn't be any noticeable delays no matter what approach you take. And your simple math is flawed, if your request is early in the queue then it actually makes it take longer to process (depending on how large your thread pool is).
  21. Scalable? He writing a chat bot and unless he's running on a multi-proc system more threads would just slow things down.
  22. Why would you need multiple threads? A simple queue would work fine.
  23. Thankfully in 2.0 they have the StopWatch class.
  24. Thought I'd make my post hard to read too. :p Use DateTime.DayOfWeek Edit: Ya, the ToString method might be easier in your case.
  25. It all depends on how you want to use the data.
×
×
  • Create New...