A common mistake, if you have written something worthwhile you need to look at protecting the idea not the code. Your code is protected through copywrite but can be easily coppied should someone want to - read around the early days of microsoft. You have to prove that someone else has seen your code before you can claim it has been coppied which is virtually impossible.
Protect the idea if you think it is really worth it, however it is a bit of a catch 22, if the big boys think it is worth anything they will challenge it and it will cost a fortune to persue. If they dont challenge it its probably not worth doing!
I read something years ago about how companies were trying to patent every tiny thing. Although it was a few years ago some companies like Intel I believe had thousands and thousands of pending ones. There were some weird ones and I think ebay even tried to patent the buy it now feature.
Sadly code is kind of like words, its just a rearrangement of already existing ones(great example in the movie Flash Of Genius with Greg Kinear). As Lewcy said, if its really that important, do it, otherwise, just try not to let it get out or encode it for some protection.