free geoip Jayson's Blog - jaysonKnight.com
jaysonKnight.com
A conduit to the voices inside my head.

Jayson's Blog

  • .Net String Stuff

    this article is a continuation of an earlier post

    after gorging myself over the holidays, i got to thinking about the .Net framework handles string types (what goes better w/ turkey than thinking about code?).  there is a tool located here that i sometimes use to profile libraries i write/hijack for performance and just to see what's going on under the hood.  it's the .Net equivalent to SQL Server's query analyzer execution plan, though in my opinion much more powerful.  the 2 biggest performance mongers in .Net (expectedly) are boxing/unboxing, and string concat'ing.  i will save boxing/unboxing for another post, wanted to touch on how .Net handles strings.  

    all primitives in .Net are stack based value types except for the primitive type 'string'...despite the value type syntax for instantiation/assignation, it is in fact a heap based reference type.  the fact that .Net has a built in type for strings comes as a great relief for C/C++ guys as strings in those languages were nothing more than an array of characters (while not entirely different in .Net, at least the wrapper 'string' class has already been written for us allowing us to focus on more important things than writing our own).  here is the caveat of .Net string types though:  they are immutable.  take the following code for instance:

    string s1 = “a string”;  string s2 = s1;  Console.WriteLine(”s1 is “ + s1);  Console.WriteLine(”s2 is “ + s2);  s1 = “another string”;  Console.WriteLine(”s1 is now “ + s1);  Console.WriteLine(”s2 is now “ + s2);  Console.ReadLine();

    the output of from this is:

    s1 is a string  s2 is a string  s1 is now another string  s2 is a string

    in other words, changing the value of s1 had no effect on s2, which is contrary to what we'd expect with a reference type.  once a string type is initialized with a value, that particular string type will always maintain that value, it will never change.  which brings me to my second point, the overhead required for concat'ing strings.  so what happens when you declare, initialize, and then try to concat another string to an existing string?  an object of type System.String is created and initialized to hold just enough memory for how many ever characters are in the string.  when you code up a concat (someString += “some more text here“), it would appear syntactically that “some more text here” is simply being tacked on to the end of someString, however this is not the case.  what is really happening is that an entirely new string is being created with just enough memory allocated to store the combined text (if someString.Length = 40 and you want to append 60 more chars to it, the CLR creates an entirely new string that is 100 chars long), then the memory address is updated to point to the new string (and assigns the var name to someString), and the old string is orphaned and will be cleaned up when the GC comes along (which for the most part is out of our control).  i won't supply an example here, but clearly if your application makes extensive use of text processing (such as the project i am working on right now, more on that later), it will run into some pretty severe performance problems.  so, fortunately for us MS has supplied the StringBuilder class that lives in the System.Text namespace which alleviates most of the memory issues associated with repeated string concat's.  i won't bore anyone with specifics as to the inner workings of the StringBuilder, but basically when the Append method is called, the same block of memory that the StringBuilder occupies is updated with the new string, and if the StringBuilder runs out of allocation space, it roughly doubles its' own size transparently and keeps on truckin' without mangling your application's memory usage.

    one of the projects i am working on right now is creating a flat file for our end of year tax application to consume (fortunately our parent company is actually processing this file for us, unfortunately their system is written in COBOL so it expects a very specific file format with large amounts of whitespace/zeros between fields, the file itself is 2071 bytes wide and each and every byte needs to be occupied by a specific piece of data, be it something pulled from our DB, or whitespace).  i initially set out to write it as a procedural class in C# utilizing lots of calls to StringBuilder.Append, however this quickly became very tedious as literally in hundreds of places i was making calls like “StringBuilder.Append(”                    “) <-- in this case appending 20 spaces as a field delimeter for the file (in some places the specification calls for literally 200 spaces between fields, extremely tedious to code by hand, of course i can code a loop for that, but it's redundant to do this in hundreds of places).  i don't like redundant code, and i especially don't like redundant loops, code can become obsfucated using this approach, plus keying in all the spaces by hand is error prone, not to mention that the specification is written per byte and is inclusive (in other words, if it calls for bytes 200-220 to be keyed as spaces, it's actually 21 spaces, not 20).  so i set out to write my own text processing library to handle all of this for me.  the result has tidied up the original file building application by hundreds of lines of code, and the memory savings by using a StringBuilder is substantial.

    the functionality of the StringManagement class i wrote encompasses the following behavior:  provided with an array of the delimeting characters, the number of times to append these characters, and an array of strings...return a nicely formatted string or StringBuilder object (with the trailing delimeters removed from the final string in the provided array, otherwise you'd end up with the following if you wanted 5 spaces delimiting your text  “some text     some more text     even more text     “<-- note the 5 spaces after the last string, these will be removed by this library).  here is the source code.

    Note that the BuildString method accepts an IDictionary parameter...i recommend using a ListDictionary, i originally wrote client code using a HashTable object, however you have no control in what order the key-value pairs will be read during enumeration, so the delimters will more than likely be written in a different order than you would like.  a SortedList of course will be sorted by the key, and index positions can change internally, so that doesn't work either.  i am in the process of finding another suitable collection item as ListDictionary is recommended only for 10 values or less.  i will add overloaded methods as i think of them, recommendations are always welcome.  sample client code is in the /// summary section of the BuildString method.

  • MS Request from Linux Users

    Now this is certainly an interesting article.  I will refrain from commenting until i can formulate somewhat of an unbiased opinion.
  • VS.NET Project File Tips and Tricks

    This post reminded me of a system i came up w/ a while back to make managing vs.net projects a bit simpler from an administrative standpoint (indeed, exactly what is mentioned in the post).  when you add projects to a .net solution, the path to that project (if it's non FPSE web apps and all others) is hardcoded into the .sln file as an absolute value, so if you were to change a drive letter, or decide you wanted to move all your projects to a shared drive, etc vs.net would have no idea where to look for those projects, and as shannon mentions you are not given a browse option when it can't find the project, so you would have to remove/re-add each project individually...a royal pain by any standard and certainly not very condusive to productivity.  it's actually a pretty easy workaround, and if implemented early on, it can be a real timesaver down the line.

    map a virtual drive to your VS projects folder, then in VS props change your Environment/Projects and Solutions location to this virtual drive letter. from this point forward no matter where you save your .sln file, it will reference projects using using the drive letter (the caveat here being you need to save all your project files in the same directory, which is probably the best thing to do anyways). sharing your VS projects file (with the appropriate perms) and then using a UNC name in VS Environment/Projects and Solutions property should provide the same functionality as well. i don't know how windows ACL GUIDS will affect the latter if you format, i am assuming the value is simply stored as a DWORD in the reg and VS won't do any ACL GUID checking.  for web projects the process is very similar, simply change the Local Path prop in the IIS MMC console for the root web site dir to a UNC name (this will take some security tweaking in the sharing properties of your web directory on the file system, if you duplicate the settings on the security tab you will be ok, however you probably won't . VS.NET will then hardcode these values into SLN files (this applies to non FPSE web projects...if you use server extensions it won't matter, the value will be http://localhost/[project name]). if you format/change your working directory path, etc, all you need to do when you are done is redo the drive mappings/folder sharings, change the settings in VS.NET, and you should be good to go. i personally use drive mappings and haven't run into any issues when it comes to swapping out drives, so long as i've kept my project files nice and tidy.

    hopefully this makes some sort of sense...if you actually walk through the steps you will see what the end result is, the actual location of your project files doesn't matter as long as you use some sort of pluggable name for the path (in this case UNC names, or virtual drive letters).  cheers

  • Letter to the CEO of Lindows

    i wrote this letter to the CEO of Lindows back when the idea was first incepted as a Windows desktop replacement (this letter is circa april of 2002).  while i applauded what they were trying to accomplish at the time (completely erradicating MS from the desktop...or perhaps providing some true competition), the developer in me wanted details as i have made my living using tried and somewhat true MS tools.  at the time, they were claiming that 90% of native Windows apps would run on Lindows out of the box, which seemed a bit far fetched as one of the things MS is best at is being proprietary.  not that my letter had anything to do with Lindows reversing their initial claims of a true Windows replacement (they now claim nothing more than being an uber user-friendly distro of Linux), but shortly thereafter i guess they realized that there is more to a desktop/[platform] than a purdy pricetag and a friendly GUI.  besides Office sales, MS indirectly makes the majority of the rest of their money pitching Windows (and now .NET) as a platform for developers (read --> extensible for corps to increase productivity, and thus utlimately revenue).  i myself personally could care less about any of the above (the corporate world begs to differ i am sure)...my bottom line is time to market and ROI.  bear in mind i wrote this during the ensuing lawsuit that MS brought against Lindows for trademark infringement...thus there is a bit of sarcasm and probably some naivity; here is the email i sent to him (and needless to say, i never heard anything back...they actually thought it was a product support request which is strange as the product wasn't even released yet):

     
    From:      Jayson Knight (jaypatrick@carolina.rr.com)                              Sent:  Mon 4/8/2002 7:19 AM
    To:           'michaelr@lindows.com'
    Subject:  a little late
     
    i am curious what kind of opportunities you are going to expose for the development crowd out in the world.  if you are positioning Lindows as a viable business alternative to Windows (pls note the capital 'W') then understand that most companies are interested in MS products due to the extensive customization that can be done via (albeit proprietary...though remember you are positioning yourself against MS here) VBA, COM and other technologies (OleDB, ActiveX) to tailor these products to the corporations needs.  i myself am a developer and as such am not particularly interested so much in the bottom line as i am what i can do with a product.  sure aesthetically many Windows (capital 'W') pograms may run on Lindows...but under the hood are they really the same?  what kind of gaurantees can you give the millions of Windows (capital 'W') developers out there that the very same MS products will perform and accomplish the very same results as compared to the Windows (capital 'W') version?  surface layer integration is easy, for the average office worker this would suffice just fine, however show me a corporation who does now customize MS software for internal needs and i will show you a who's who of companies that simply are not leveraging this software for all that it is worth.  i have hundreds of thousands of lines of VBA and VBScript code that would need to be ported to the LindowsOS...what kind of mechanism are you offering to make this as seamless as possible?  The simple fact alone that any customizations to MS office (read anything MS) depends on core MS kernel libraries and Windows (capital 'W') API calls is enough to make me beleve that any company with ANY kind of financial investment in MS products simply will not be able to make the switch to Lindows because of the Lindows OS architecture alone!  It has nothing to do with the bottom line at this point, appearance is quite important, though it runs a very distant second to functionality and integration.  This is the "bottom line" so to speak..what can the software do for the enterprise.  MS's proprietary nature alone forbids this on any other OS except for Windows (capital 'W').  And this is the very aspect of GNU based OS's that has prevented them from gaining any kind of ground in mainstream computing thusfar when it comes to trying to run MS software.  Which brings me to the WINE project that has been ongoing for years.  It would be simply amazing if Lindows has accomplished in the short time since its inception what WINE has been striving to succeed at FOR YEARS, though not be it an unwelcome change.  Give us (corporations, enterprises) a new OS that runs MS software aesthetically and functionally as well as the Windows (capital 'W') counterpart at a fraction of the price and you will have succeeded in your goals.  Aesthetics will not be enough though.  Perhaps to the end user yes, but how many of them TRULY know what is going on behind the scenes?  It is the IT departments that drive software sales in the corporations, where the bottom line is not about dollars, but productivity and ease of use.  By positioning yourselves against Microsoft and Windows (capital 'W') you may have inadvertantly sealed your own fate.  Apple has succeeded by capturing a niche market, as has Linux and other GNU based OS's...but have they really succeeded in the areas you are trapsing upon now?  Not in the least...
     
    That being said, I will say I admire what Lindows is trying to accomplish.  Who doesn't want a shortcut to greatness.  But please give us an indication of what is going on under the hood as well.  CFO's may be jumping for joy at this opportunity, but I can guarantee you that CIO's and CTO's alike are sweating about what to do when the order comes to migrate to LindowsOS...what to do with existing codebases for Office apps, VB apps, pretty much any existing MS code that simply will cease to function without Windows (capital 'W') core libraries to support them.  The cost of porting alone will prohibit most companies from this migration.
     
    I look forward to your reply about the underpinnings of LindowsOS as to what it will and will not support...from a developers standpoint.
     
    Thank you,
    Jayson Knight
  • It was Only a Matter of Time

    I am sure we all saw it coming...Real has finally decided to take on uncle bill and the boys in redmond.  while i may not agree with microsoft's alleged actions, history may bear repeating itself (ala netscape, sun, etc).

    i will be following this with a sharp eye.

  • Great Article About the .NET GC (Garbage Collector)

    have a look at this article for more than you ever wanted to know about .NET GC.
  • .Text - take two

    i have been wrestling with trying to get the source version of .Text to run for the last 2 hours and have hit a roadblock.  here is a description of what i am running into, basically that no content was showing up when i compile and run from VS.NET, even though it's pointed to the same DB that my production blog uses.  so i decided to get under the hood to try and figure out what is going on and this is what i discovered.  basically, the way that the DB is designed is that the blog_Content table keeps track of the content according to the BlogID field in blog_Config which in itself is fine.  however, the BlogID is unique per host name, in this case i have the hostname 'zerotrilogy.gotdns.com' mapped up to BlogID field '0', ... {rows of other hostnames} ... all the way to localhost (as when you compile and run, this is the hostname), which is mapped to BlogID field of 0 + n (where n is the number of rows from zerotrilogy.gotdns.com).  the issue is that since there is a different BlogID associated with localhost, it maps up a fresh set of content from the blog_Content table...of which there is none.  so i thought it would be wise to start hacking around in the blog_Config table to get all the BlogID values to be the same as my production site (0)...dropped the primary key, removed the identity, and manually numbered all the values to '0' (the only things i did do right in the end were backing up the db first and scripting the table out to a .sql file).  initially this worked fine, all the content showed up as expected, i was able to push new code over to my web server, etc.  of course when i started trying to change config settings via the .Text admin console, it all blew up to hell as sprocs were looking for primary key refs on BlogID in blog_Config.  the DB restore didn't work (guess that doesn't store schema changes?), so i dropped the table and brought it back via the SQL script.  i then started getting invalid cast exceptions and it took me another little while to realize that for yet another unknown reason, the table script didn't script out the default contraints that are defined in the create script for that table (NULL values were being store in the columns, and i guess .Text didn't like that too much).  i ultimately had to pick through the sql build script that shipped with .Text and pick out all the blog_Config DDL statements to get that table back.  i was about to rant and rave about the design of .Text, but just realized something embarassingly simple...see below

    even as i post this blog, i just realized that there is a setting in blog.config where you can hardcode the host and application name, it's the last couple of lines.  that's what i get for not RTFM :-)

    first order of business now that i have source code up and running is to get rid of that god awful orange XML icon linking to syndication.  cheers

  • What will they come up w/ next?

    Stumbled across this article this morning, perhaps they will find the gene for free will/autonomy next?
  • Really cool web service front end

    I came across this tool a few weeks ago.  It's basically a very well done frontend to a web service backend.  It's a great example of what can be done with web services, in essence making this application a distributed “smart client” windows forms app.  a lot of companies are moving to a similar type architecture for internal systems where the actual business logic for any and all apps (winforms or other) is processed from an app server.  the advantage to this of course is easier maintainability and extensibility of product features...need a new component?  just add it to the app server, zero touch deployment with the richness of the GDI platform.  this application is probably the first i've seen of it's type for consumer use, and to be honest it's flat out amazing how powerful this application is.  i highly recommend dl'ing the demo and playing around with it.

    //j

  • RSS is working now

    the .Text editor had mangled a break tag to look something like this “<BR=””, needless to say that the parser didn't really care for that combination of characters too much.  the next thing i have to figure out how to do is have the feeder feed all blogs, as of now it appears to only be syndicating the last 20 posts.  knowing my luck it's buried in a sproc somewhere, so until i have the energy to track it down, 20 will have to be enough.  even better it's probably just a config setting i am overlooking :-)

    i got some interesting news at work today.  it's something i already indirectly knew but it was made official.  our team is splitting up into two groups based on tenure (consultants/contractors are at the bottom of the ladder)...a Production Support team and a project team.  the other consultant at work and myself will be handling all production support issues on systems that have zero documentation, and half the developers that wrote them aren't even there anymore.  i am certainly not complaining, i'm just sick of being in a support type role, and we're already understaffed as it is.  i really miss project work, but hopefully the Keane position will come through.

    emperor chinese sounds like the grub option for the evening.  cheers  //j

« First ... < Previous 84 85 86 87 88 Next > ... Last »

Copyright © :: JaysonKnight.com
External Content © :: Respective Authors

Terms of Service/Privacy Policy