Archive for category General Programming
.NET StringBuilder — Fast, but not as fast as you think!
Posted by eric in C# Programming, General Programming, Microsoft .NET 3.0 / WinFX, Reverse Engineering on May 28th, 2009
I recently ran into a situation where I was tasked to profile some .NET code and do some optimizations anywhere hot spots popped up. I was amazed to find out that one of the BIGGEST offenders in our code block was a simple call to StringBuilder.Append(char). I had to take a step back and scratch my head and wonder if my profiler was confused.
I re-ran some tests using the StopWatch class to hard code some metrics into the application and they also confirmed the findings. What’s up? How could a class that everyone says you can use to your hearts content when it came to string concatenation was failing me?
Turns out, it was a mix of misuse and a common misconception about the StringBuilder Class.
Example Huffman Compression Routine in C#
Posted by eric in C# Programming, General Programming on May 22nd, 2009
This last week I decided to sit down and hash out a simple Huffman compression routine using C#. I’d never created a compression routine before from scratch (my past implementations were static for the sake of time savings), so I fleshed one out. I know that many examples exist elsewhere on the net…. but they all seemed overly complicated and up their own ass
I had a couple goals in mind while creating my routine:
1. KEEP IT SIMPLE — A lot of routines out there WORK, but their code is too overly complicated for their own good. This over complication leads to slowness which brings me to my next goal
It should be a simple class that accepts input data, with simple public accessors that are easy to understand even for the novice developer (sorry folks, no asynchronous delegates).
2. MAKE IT FAST — When dealing with large amounts of data in C#, especially when running it through an algorithm, it’s all too easy to use all the handy built in virtual methods or using other build in tools which make coding easier with speed being the sacrifice. Die hard C++ developers will point to these routines as C#’s downfall as a legitimate language when it comes to data intensive tasks.
XBox 360 freezing while watching a DVD movie == SAD PANDA!
Posted by eric in General Programming, Hardware, Opinion on September 3rd, 2008
I’ve been on a minimalist kick recently regarding my home theater upgrading my receiver to an upscaling Denon AVR-2308CI receiver and then removing all components I never really use. Part of this process was eliminating a DVD player when my XBox 360 is (or at least should be!) capable of playing standard DVD movies. Sure, it only puts out a 480p signal but the Denon handily upscales the incoming video to 720p for output to my TV.
Sounds simple, right?
So of course now when my wife and I actually sit down to play a DVD movie, randomly it’ll just freeze the picture and appear to lock up. It’s not a hard lock as my XBox still responds to IR commands (open/close the tray, power on/off). At first I suspected the Denon receiver as it is taking the video from the XBox in using component and scaling it out via HDMI. Multiple restarts and power on/offs of the receiver and the picture wouldn’t unfreeze meaning the XBox 360 itself had locked up.
What the hell!
I’m sure there are some who are at this point thinking, “Your XBox is defective!”… I would completely and 100% agree (as I’m on my 3rd one), but I can play titles like Bad Company and Arcade games for hours with no problems, so I doubt it’s a hardware defect within the machine itself.
I suppose I’ll swallow a big ole’ slice of humble pie tonight and call Microsoft Support, BUT, just in case they find nothing wrong I’m curious if anyone else has had this issue!
Thanks!
Let’s take a dive into XCode and Objective-C!
Posted by eric in Apple, General Programming, General Software, iPhone on August 6th, 2008
So, I’m diving into the pool!
I recently purchased a MacBook Pro for the sole purpose of developing software for the Mac/iPhone platform. It’s completely unknown to me and currently the XCode IDE looks nothing if not completely confusing compared to the friently intuitive interface of Microsoft Visual Studio that I’m used to
What brought me to this point? Well, two things.
First, I’ve been wanting to dive into Objective-C for a little over a year now and started dabbling with it a while back on my old G4 Powerbook. I was impressed with the coolness of it, but being that I was developing on a G4 Powerbook, I was limited as by this time Apple had begun the mass migration to Intel based systems.
Second is that I want to develop applications for the iPhone. Not to make a mint or anything, more or less because I think I have some good ideas on programs people would use. Like how Apple provided the iTunes controller, well, hows about a WWWinamp controller for the iPhone? Perhaps one that lets you search your library locally on the iPhone without even connecting to WWWinamp?
I started down this path because there’s currently a program for sale on the iTunes App Store that lets you control your instance of WinAmp remotely… for $4.99!!! What the crap?! I was floored that the author would expect that kinda money for a program when there are PLENTY of other FREE alternatives out on the web (like WinAmp Remote, AjaxAmp or WWWinamp). I made it my mission to release a comparable program
It’s just going to take a month or so to ramp up on the new IDE and learn how to do SOAP calls and whatnot. Should be a fun adventure though! My wife begins the final semester of her Teaching Credential program in a couple weeks, so I’ll have four nights a week alone to myself to nerd out and gorge on Hot Pockets!
I have another version of WWWinamp in the works as well. This is basically some code modernization for sections that I wrote over a year ago. Updating things to use Generic Methods and whatnot. You know, fun .NET stuff
Cheers!
WWWinamp v4.2 Build 2990
Posted by eric in Apple, General Programming, General Software, Internet, WWWinamp, iPhone on March 9th, 2008
Well, after about a week of off and on work the latest version of WWWinamp is ready!
I’ve taken the “beta” tag off of it as it seems the recode of the HTTP request processing seemed to work without issue and no bugs were reported (other than the ‘paging’ issue, which really was a defect in the script parser).
Changes for this version are:
- [HTTP] Daemon will now start if a WinAmp instance is not found
- [HTTP] Able to specify max number of HTTP threads to process (Default 25)
- [Script Parser] Fixed “Paging” issue when searching through the Libary
- [Script Parser] Script Files (*.wwa) will be run from the same folder as the file requesting them
- WinAmp Handles will be updated if a new instance is detected
Be sure to use the latest config file included with this release as it has a new key value, WWWinamp.HTTP.ListeningThreads, which tells the HTTP daemon how many threads to use max. This is set to 25 by default if no key is found, but it will throw an error. So if you don’t want to use the packaged configuration file because you’ve hacked together your own, you can manually add this key with any value you’d like.
This value isn’t a huge addition but it can help maintain system stability under heavy load. This way WWWinamp won’t spin up an infinite amount of threads if there’s heavy resource contention or there’s a problem that is causing threads to hang.
Also, the other ‘fixes’ were requests made by ‘dawolf’ here in my blog so I suggest more people get involved and we can make WWWinamp better!
In addition, if you’ve made your own skin and want to share it, please feel free to contact me and I can post it here to my blog for others to use.
As for future releases, they may be a little slow in the coming month. I’m going to be diving into the iPhone SDK and Objective-C programming using XCode on my Apple. I think a remote media interface would be totally awsome if I can have a native WWWinamp application on the iPhone talk to the WWWinamp server using WCF/SOAP. It’d be way easier than using the webkit crap and I could make it have a lot more functionality (perhaps tuning in to a shoutcast stream VIA the iPhone?). Anyways, just thought I’d give you guys a little bit of information on that.
Cheers!
WWWinamp v4.2 Build 2990 – Download (56k)
WWWinamp iPhone Compatible Skin — COMING SOON!
Posted by eric in Apple, General Programming, WWWinamp, iPhone on February 1st, 2008
Ever since the Apple iPhone was released last year, I was blown away by the multimedia and browser capabilities of it. I started wondering from the get-go about the actual usefulness of a software development kit that only allowed for development of applications in a mobile browser.
It was then announced that the official iPhone SDK which runs natively on the iPhone will be released later this month. So soon you’ll have a host of local applications which will most likely include 3rd party media players. It then dawned on me, if a user could use WWWinamp from the iPhone with an interface that interacted nicely on the iPhone, then someone’s iPhone could act as a remote control from ANYWHERE allowing them access to their home media library.
Well, this is just a heads up that I’m currently working on a skin for WWWinamp that will let it work on the iPhone (better)! Soon you all will be able to control your media center or home copy of WWWinamp from anywhere using your Apple iPhone!
I’m still working on the organizing the data on the screen in a manner that makes sense and is easy to use. All the functionality that comes with the default skin will be included in the iPhone version, including cover art and all the Winamp Playlist functions.
It’s actually pretty sweet controlling Winamp from an Apple iPhone and I hope I can polish this up and put out a beta version this weekend.
I’m still trying to fish up some resources on the WebKit API and the WebKit specific tags to make things integrate nicely.
Keep your browsers posted here for updates in the coming days!
A new version of WWWinamp is coming… I SWEAR!
Posted by eric in C# Programming, General Programming, Microsoft .NET 3.0 / WinFX, WWWinamp on January 21st, 2008
Hello Everyone!
I’m currently working on the latest version of WWWinamp after taking another hiatus from the project in order to clear my head and work on some other fun things such as the previously mentioned XNA projects
The next version of WWWinamp will be targeted for the .NET 3.5 Framework and you will need to have it installed on your machine in order to run WWWinamp. Most of the changes in this version are behind the scenes and will probably be transparent to you, the user. BUT, some visible changes in the upcoming version of WWWinamp 4.2 will be:
- Automatic Version Checking for new releases of WWWinamp
- Ability to enable or disable Automatic Version Checking
- Ability to enable or disable Windows Vista warning message
- Improved performance under load
I know, nothing earth shattering on the horizon. “Why is this?” you might as. Well, the honest reason is that I haven’t received any bug reports with issues that weren’t related to a misconfiguration or user error. This is a good thing! It means that WWWinamp is stable and there aren’t any horrible bugs that continue to nag users. The downside to this is that because WWWinamp is pretty feature rich as is, I’m running low on ideas that could be implemented.
An idea I’ve tossed about and am thinking about trying out is creating a WWWinamp .NET assembly for user within your own Windows or ASP.NET applications developed using the .NET framework. The assembly would handle the media library and searching of the library so you wouldn’t have to code your own database and file searching routines, as well as handling the unmanaged code required to interface with Winamp (if it’s running locally on the WWWinamp machine) or communicating via WCF to a remote instance of WWWinamp running the WCF daemon.
I think that between the WWWinamp Server and my proposed WWWinamp Assembly, that’d give both advanced and novice users full control over their setup.
As I mentioned in a previous post, I’ve moved WWWinamp into Visual Studio 2008 with Team Foundation Server. Within the latest version of Visual Studio 2008 there is a set of code analysis tools which calculate such items as Code Maintainability and Cyclomatic Complexity. I ran it on WWWinamp and it scored the following:
Maintainability Index: 83 (out of 100)
Cyclomatic Complexity: 636
Depth of Inheritance: 7
Class Coupling: 151
Lines of Code: 1,829 (!!)
After over a year, I think WWWinamp has gotten better and continues to improve with every version!
Big thanks to everyone for their support and keep your eyes peeled here for the latest version of WWWinamp!
2D WndrPong! using the Microsoft XNA Game Studio v2.0!
Posted by eric in C# Programming, Gaming, General Programming, Microsoft XNA on December 28th, 2007
I decided to take some time this weekend to sit down and learn what I could about the latest release of Microsoft’s XNA Game Studio. I started out with a book I purchased called Microsoft XNA Game Studio Creators Guide, which turned out to be a terrible book. Most of the examples in this book assume that you’re starting with a project the book provides on a Website, which already has hundreds of lines of code, custom shaders and everything built in… without even explaining how the code is working in the background.
After fumbling around with that for an hour or so an only succeeding in creating a small square on the screen, I headed over to Microsoft.com to see if any MSDN articles might exist to help me along in my ‘ground up’ learning of XNA. I was pleasantly surprised when I found a great article titled “Your First Game: Microsoft XNA Game Studio in 2D“. This was EXACTLY what I was looking for as it starts from the ground up, assuming the reader has never done game programming before, let alone 3D game programming.
The example provided my Microsoft in this article is a simple 2D Texture of a cat that bounces around the window. I was so pleased with the ease of coding this, I thought to myself, “Heck, how hard could it be to recreate Pong?”
So I set upon my task.
Several hours and many Coca-Cola bottles later I had not only my first XNA game running in Windows, but after purchasing the XNA Creators Club annual subscription from the XBox Live! marketplace for $99, I had it running on my XBox 360 as well
I decided to take a little extra time and add a debug information screen as well as a small welcome screen
Controls (PC):
Up/Down for Player 1 Paddle (Left): Q/A
Up/Down for Player 2 Paddle (Right): Up Arrow/Down Arrow
Debug Information: F1
Controls (XBox 360):
Up/Down for Player 1 Paddle (Left): Left Thumbstick on Player 1 Remote
Up/Down for Player 2 Paddle (Right): Left Thumbstick on Player 2 Remote
I did run into a couple of ‘gotchas!’ while working with Game Studio. The major one I had trouble with was when you’re developing for the XBox 360 you have to account for overscan on the Television and have your game render within the ‘Safe Area‘. I noticed that when I was playing my Pong! game on my LCD TV at 720p, the edges of the game were cut off and it looked like it was stretched past the borders of my TV. After asking the fine folks in #XNA on IRC about this issue, they were able to help me out. Now I have my Pong! game account for this by setting up an XBox 360 macro which pads the edges of the play area by 50 pixels.
I’m including the Source Code for my version of Pong! which I’ve titled, “2D WndrPong!”. You can work in XNA Game Studio for free using Visual C# 2005 Express Edition along with XNA Game Studio 2.0
To deploy your games to an XBox 360, you must pair your XBox with your PC (using the “XNA Game Studio Device Center” tool) then you must purchase an XNA Creators Club Membership from the XBox 360 Marketplace. I believe the prices are $49.99 for 3 Months, $99.99 for a year. I opted for the entire year since I know it’s going to take me some time to learn
Baby Steps
2D WndrPong! Source Code – Download (36k)
WWWinamp is being converted to .NET Framework v3.5!
Posted by eric in C# Programming, General Programming, WWWinamp on December 5th, 2007
Yep, it's true!
I've spent the last week or so playing around with the .NET Framework v3.5 and I really like what I see. Microsoft has also put a lot of work into Team Foundation Server 2008 as well. I've setup a Virtual Machine using Virtual PC here running Team Foundation Server 2008 on Windows 2003 Server R2 and was able to get WWWinamp imported + converted without issue!
WWWinamp in Team Foundation Server 2008
You need to enable javascript to view the content.
Power Thumbnail Powered By CodeXpress.CN
One thing I have noticed is that TFS does take up quite a bit of resources. I had to kick my VM up to 2GB of RAM in order for it to handle and build WWWinamp without hitting the swap file. Something to keep in mind moving forward I suppose. I'd imagine a large installation of TFS would require something along the lines of a Quad Core CPU with at least 4GB RAM.
There are several features in .NET 3.5 that I plan on implementing in WWWinamp right off the bat:
- Object Initializers - This will really help clean up the already massive code base. It'll also speed things up a bit
- Embedded Manifest - A feature I'm surprised they didn't implement with the release of .NET 3.0. Now the .manifest file will be embedded into WWWinamp, so you won't have the extra file handing around if you run Windows Vista
- Extension Methods - Again, this will help clean up the code base and make things faster. I imagine it'll take up a little more memory, but these days RAM is abundant
Now, I see LinQ and I'm trying to figure out it's role in everything. I think it'll make DB communication easier but I'm not a fan of the anonymous data types and implicit local variables. I think it could lead to some sloppy coding methodology if not kept in check.
I think it's handy that you can now run a SQL like statement on a generic, but I'm wondering what sets this apart from the FindAll method that already exists in System.Collection.Generics. It does make it easier though to search through a Generic Collection for a developer who doesn't have a solid grasp on delegates.
So, all that said, things are moving along. I'll keep you all updated on the progress and please, send in those feature requests!
Discogs.com API Assembly for .NET Applications v1.0 Build 2871
Posted by eric in C# Programming, Discogs API, General Programming, General Software on November 12th, 2007
Greetings Everyone!
I've been working on the Discogs.com API Assembly for .NET Applications now for a couple days and have been able to make some progress. It's now a bit more stable as well a a tiny bit easier to use.
I took some time and added a DEBUG class. This class allows you to find out what's happening within the Discogs.com Assembly if you start to have issues!
This new class has two properties:
- Verbose (bool) - If set to TRUE, Verbose logging will be enabled allowing you to get more precise detail on what is going on within the Assembly. Otherwise, only exceptions will be logged.
- Log (string) - This is a string containing the current debug log.
Also, it has one Method:
- LogEvent (string sEvent) - Logs the value passed in to the debug log. This way you can use the same debug log from your own applications
Should help make things a little easier.
New in this version as well is better error handling in the event of 404's or an Artist/Release isn't found. Before if you requested something that didn't exist, the Assembly kinda crapped out while trying to deserialize the (non-existent) XML
This has all been fixed.
I'm also including a small example program (with source code) on how to use the Discogs.com API Assembly. I've coded the example in C#, so sorry to all those VB.NET developers out there!
If one of you guys would like to translate it to VB.NET, I'd be more than happy to post it here as well.
If you do not already have Microsoft Visual Studio installed, no worries! Microsoft provides a free version for C# development called Visual C# Express and you can get it here over at Microsoft.com.
You will need to update the Reference to the Discogs.com API Assembly. It currently points to where I had it setup on my local machine. ![]()
Any and all feedback is appreciated!
Cheers!
Discogs.com API Assembly for .NET Applications v1.0 Build 2871 - Download (9k)
Discogs.com API Assembly Example Application (with Source) - Download (10k)

