Getting My ‘C’ Legs Back
After some further pondering, I decided that the performance was bad enough to warrant a diversion into the world of C extensions to Python. The actual format of a C module is very simple indeed, you simply accept Python objects as function arguments and return a pointer to a Python object on exit. The Python libs deal with all the conversions and then there’s a straightforward structure for declaring the module interface. Not a problem at all.
The problem is getting to the point where you can build the thing. The main Python docs talk about the VS IDE, which I’m not about to buy in order to speed up my map editor, then there are various pages that discuss using MinGW and the MS Toolkit for compiling extensions, none of which seem to agree with each other. Eventually, I tried the instructions here, and apart from the IDs and directories being wrong for my installs, it worked very smoothly for me, so cheers to Mike Fletcher there. It still took a couple of hours to dig out the instructions, download the various frameworks and tools and get started on my own module though.
I had hoped to be able to post with some comparison timings (showing a — cross fingers — massive speedup), but I simply haven’t got that far. My C coding powers are weak from years of neglect, and I’m ashamed to admit that I actually had to look up how to dynamically allocate a three-dimensional array. Pointers to pointers to pointers… totally against the Python ethos, but there’s an undeniable attraction to the rawness of C for me and I’ve missed it. The fact that Python allows me to choose to drop down to that level as and when I feel like it makes me like it even more.
Hmmm… maybe I can inline some assembly in the C code.
Anyway, I’ll get this finished by Saturday (I tend to watch a movie or catch up on some TV on Friday). I’ll be interested to see what sort of speed boost it provides.

