Blog Stats
  • Posts - 99
  • Articles - 5
  • Comments - 236
  • Trackbacks - 105

 

Under the covers

Things most people don't care about.

C# FP Math Leaky Abstraction

Some you have probably seen a post from last Tuesday entitled Floating Point Fun. If you have not read this I would recommend going back and reading it before continuing. In this post I discuss some of the interesting things that can happen when dealing with floating point math in C#, it is important to note that these items did not happen in version 1.x of the framework. The root of these problems is that when in a register the floating point is treated with a different precision than when it is...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Floating Point Fun

I am sure by now that most know how floating point approximations work on a computer.. They can be quite interesting. This has to to be the weirdest experience I have ever had with them though Open a new console application in .NET 2.0 (set to build in release mode /debug:pdbonly should be the default) it is important for me to note that all of this code runs fine in 1.x. Paste the following code into your main function float f = 97.09f; int tmp = (int) (f * 100.0f); Console.WriteLine(tmp); Output:...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

String to Int []

I apologize for the code not being indented , I am using word 2007 and no matter what I do it does not seem to want to indent properly (I have tried copy/pasting to notepad, you name it), if you know how to get this working please contact me. See picture of word version http://geekswithblogs.net/i... update I manually indented all of it but I am still wanting to know how to avoid this Everyone seems to enjoy performance posts so …. I saw this question...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Sorting Performance .NET 2.0

Be very careful when using Array.Sort in 2.0. I had posted a bug report about this a while ago http://lab.msdn.microsoft.c... The behavior observed was originally in arraylist (which uses Array.Sort internally) so keep in mind that this applies to it as well. Array.Sort(Items, 0, Items.Length, Comparer.Default); //takes 1 minuteArray.Sort(Items2, 0, Items.Length, null); //takes 250 ms Items and Items2 are both clones...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Invoke vs BeginInvoke

Now that 2.0 (with its detection of accessing control properties from an incorrect thread) has become main stream there are numerous people realizing that they had many bugs in their 1.1 code. I could write up a bunch of information about why you need to do this but I think http://weblogs.asp.net/just... and others already do a great job of this. I am instead going to talk about how things work (that you probably don't care about). Once upon a time in a land far away there...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Random Useful Code

I don't remember where I got this (so whoever you are thanks but I can't link to you update .. http://groups.google.de/gro... some time ago but it is a quite useful (and portable) way to see if a file is a .NET assembly or not ... If you fall back to the Assembly.LoadFrom method .. you have to fail many times if you are searching many files ... In looking at this again (had nearly forgotten about it until today). It works...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

2.0 Specify Thread Stack Size

In .NET 1.x if you wanted to modify the stack size of a thread you created you would have to go through some pretty nasty code .. Here is a hint :) [DllImport("kernel32.dll", SetLastError=true)]static extern int CreateThread (ref SECURITY_ATTRIBUTES lpThreadAttributes, int dwStackSize, ref int lpStartAddress, ref object lpParameter, int dwCreationFlags, ref int lpThreadId) In 2.0 a new overload has been added to the Thread class to support alterring your stack size directly through managed code http://msdn2.microsoft.com/...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Dependent in memory assemblies

Another GREAT question in MS newsgroups today. I'm using the CSharpCodeProvider to buils some assemblies @ runtime which are never saved as files (cp.GenerateInMemory = true;).The generated assemblies are hierachically dependent on each other so I generate the "bottom" assemblies first.How do I add a dependency to another previously loaded (generated) assembly?I would be happy if CompilerParameters.Referenc... could take a System.Reflection.Assembly reference as parameter.A possible...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

More fun a'la Alois (evil)

A wee bit faster for http://geekswithblogs.net/a... ok so Jeffery had gotten it down to 0.26 seconds on my machine ... http://blogs.extremeoptimiz... did some really slick math to make things a little bit quicker. but lets have a little fun with this .. I feel like this should have a disclaimer on it. I will show why after. I have taken Jefferey's modified code and applied this dubious change to it ... THIS IS HORRIBLY WRONG...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Fun a'la Alois

Alois has put up a contest for getting the fastest Time format function http://geekswithblogs.net/a... Submitted by Bruce Dunwiddie private static string FormatFast(DateTime time) { char[] dateData = new char[12]; dateData[0] = (char)(time.Hour / 10 + '0'); dateData[1] = (char)(time.Hour % 10 + '0'); dateData[2] = ':'; dateData[3] = (char)(time.Minute / 10 + '0'); dateData[4] = (char)(time.Minute % 10 + '0'); dateData[5] = ':'; dateData[6] = (char)(time.Second / 10...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Full Under the covers Archive

 

 

Copyright © Greg Young