It's true, overflow bugs are awful. I totally agree that in non-performance -critical sections of code, give wide margins for error. In performance-critical stuff, especially library code, I'd shave off as many bits as I thought reasonable, and add appropriate asserts to ensure that any input into my data structures was in the correct range. You're right that the biggest optimisation win is to change your algorithms, but where that's not possible, second and third order effects like cache coherency, register usage, and so forth are very important. (i work in the games industry, where i get beaten if I write wasteful code :) ).
NoCake
Posts
-
The Unforeseen Problem -
The Unforeseen ProblemWarren Stevens wrote:
know this is 1995 code, but I would hope that no one is using 8-bit or 16-bit integer types when writing any new code (in the age of $1/GB hard disks)
If you know you can get away with it, why not? There's a performance consideration. If I can define a colour as 4 bytes rather than 4 ints, then the colour fits nicely into a 32bit register, I can work on an large array of colours with x4 fewer cache hits, and it'll save bus bandwidth if I transfer that colour data to, say, a graphics card. In non-performance critical code, I would agree - use ints. Horses for courses, and all that.
-
custom group controlsHi Bob, Thanks! I think I wasn't clear about it, though - I have no problem inheriting XPanel from Panel and adding child controls, but that's not quite what I want. XPanel has N child panels S1..SN, that could look like this:
+-XPanel------------+ |...................| |.+-S1--+...........| |.|.....|...........| |.+-----+..+-S2--+..| |..........|.....|..| |..........+-----+..| |...................| +-------------------+
If the user of XPanel adds an instance to a form, I would like her to be able to add controls to XPanel.S1 or XPanel.S2, instead of to XPanel directly. Which is why I wanted to handle ControlAdded, so I could pass controls added to XPanel on to XPanel.S1 or XPanel.S2. Thanks again, Andy -- modified at 10:35 Monday 29th January, 2007 (got inheritance order wrong :) -
custom group controlsHeya, I'm having problems creating a custom group control (which I'll call XPanel for now). I'd like XPanel to be a user control consisting of several sub-panels, that the XPanel user can add their own child controls to. I have two problems with this: 1) If I add an event handler to the XPanel.ControlAdded event that transfers the added control to one of the sub-panels, I get an error in a message box at design time: "'child' is not a child control of this parent". This doesn't happen if I create and add the control at run-time. 2) How do I allow the sub-panels to be selectable at design time? Will I have to write my own design-time painting and interaction code? At the moment, the XPanel appears as a big indivisible unit when I add it to a form. Thanks in advance! Andy
-
Worst Peice of Code in the WorldThat's pretty awful. My gold standard for vomit-inducing code was a render function written for a game (no names). It was a single function, 3000 lines long, and had "goto" statements jumping into loop and if statement bodies. Nobody but the writer understood it. The game shipped and was moderately successfully, but I could never look at it without thinking of the festering cancer of code lurking at it's heart. -- modified at 11:39 Tuesday 22nd August, 2006: Emphasis added to 'into'. I still can't believe that. I can understand (but not condone) jumping -out- of a loop or if statement... but into one? beggared belief, that did.
-
From Games->ConsultingHi Colin, Thanks for the good advice! I'll hold off 'till the .NET 2.0 exams come up, and in the mean time, I'll brush off my rusty db skills... (you're right about the games industry not providing much in the way of opportunities to use standard databases). Thanks again :)
-
From Games->ConsultingHi all, I've got 8 years experience programming in the games industry, mostly C++, with some C# and a smattering of other languages, and in about a year, I'd like to move on to do some consultancy work (not in the games biz - I'd like to branch out, perhaps into web development/databases). My question is: I want to buff my skill set and CV before I commit, and I was wondering if anyone had any advice as to which exams (if any) would be best. I'm currently considering an MCSD. Thanks for your advice in advance ;)
-
DLL dependency woesHi Aryadip, That looks like it worked great. Wierd that there is no other mechanism to do this apart from setting environment variables... Many thanks for the help, Andy P.S. I had a funky day.
-
DLL dependency woesHi all, I posted earlier about a problem I had with DLL dependencies in ASP.NET. I followed up saying I'd solved the problem, but I was being foolish (I'd forgotten to un-stub some critical functions that forced linking). Basically, I have the following setup: ASP.NET Page --[DllImport]--> C++ Wrapper.DLL -- [static link to] --> C++ Unmanaged.DLL "Wrapper.DLL" is in the web page \bin directory. I always get the error "File or assembly name Wrapper, or one of its dependencies, was not found". This is because it can't find "Unmanaged.DLL". If I remove all references to "Unmanaged.DLL" in "Wrapper.DLL" and stub out all functions, then the web page loads fine (i.e. I know there are no problems finding "Wrapper.DLL" itself - it must be failing to find "Unmanaged.DLL"). If I put "Unmanaged.DLL" in \windows\system32\ then the web page loads fine. If I put "Unmanaged.DLL" anywhere else, I get the "File or assembly... not found" error. What is going on here? There must be a place that I can put my DLLs that isn't the windows system folder... Andy
-
Unmanaged DLL referenced by a Managed DLL errorWell, I still don't know what the problem is. Maybe I could put the unmanaged DLLs in the global assembly repository (apparently a legal operation, not sure if it would work though). Anyhow, I followed the advice of one of my colleaues, who suggested I scrap my managed C++ wrapper class and use [DllImport]-ed functions instead (so I could specify the exact location of the DLL in the attribute parameter). This works just fine. Just to let anyone else with this problem know... Andy.
-
Unmanaged DLL referenced by a Managed DLL errorHi, I've got a real novice question that I can't find the answer to (just started with ASP.NET yesterday). I want to provide a web interface for functionality provided by a large set of unmanaged C++ DLLs. I wrapped up the critical functionality in a managed DLL, then created the managed objects as session objects on my aspx page. Just creating a 'shell' managed object that has stubbed out calls, and does no static linking to my unmanaged DLLs, works fine. When I statically link in my unmanaged DLLs, and fill out the stubbed functions, I get an error: "Parser Error Message: File or assembly name ManagedNLP, or one of its dependencies, was not found." This seems pretty straightforward - stick the required unmanaged DLLs in the right place. But where the hell is that??? Putting them in the web page root or bin directories does nothing... Also, I don't really want to have multiple copies of unmanaged DLLs floating around, so is there any way I can point IIS to the central repository where I currently keep them? Many thanks in advance for any help. Andy.