Blog

Is my head screwed on correctly?

I have literally spent a day and a half debugging one line of code. It stuns me how simple an error I made, and yet how well it managed to fuck up everything – and I mean everything, heck, the debugger failed to realise my code was doing nothing (even though windows said it running), then, when it went to prompt me with an error to say “Bad Stuff Happening” it decided to crash – so the debugging process of the debugger was crashed by a bug... A two character bug.

Basically my current project is laid out as follows:

In short I created a test case, where I would load 20 items into a dictionary with an initial capacity of 5,000 (to give a nice bit of space to play with). My problem only occurred just before the program exited – simply the program did nothing. It simply sat in a state of inaction (which was a neat trick – I didn’t think that was possible without your program being closed). I quickly ran over to The Code Project to check if they had any articles or messages which had similar errors but unfortunately they did not. So I promptly created myself an account and added a question to the C++/STL forum:

Help requested: "Debug assert failed" with process hang

In short, the line of code causing such pain was:

delete [] dictionary;

This says to delete the specified array. I now had a dictionary object which acts like an array, but is in fact a single object as far as the compiler is concerned. Unfortunately my mind did not make this distinction, instead I wrote it for an array...

I believed this line wasn’t the error - it looked very valid. In fact – the first response I got on the forum contained the error reason: [note I called dictionary 'pDict' when asking for help]

If pDict is a simple pointer, then using the array delete will Do Bad Things.

It pretty much sums up everything above... Simply all I needed to have written was:

delete dictionary;

And the whole program would have run correctly...

Relieved and exhausted,

Andrew

Spot The Difference

Sample 1:

template <class KeyType, class ValueType>
keyValuePair<KeyType, ValueType>::keyValuePair( void ) {


this->key = *(new KeyType);
this->value = *(new ValueType);

}

Sample 2:

template <class KeyType, class ValueType>
keyValuePair<KeyType, ValueType>::keyValuePair( void ) {


KeyType *nKey = new KeyType;
ValueType *nValue = new ValueType;

this->key = *(nKey);
this->value = *(nValue);

delete nKey;
delete nValue;

}

Well I just spent a few hours before I realised what needed to be done. The first sample causes a memory leak, since the memory for a new variable of KeyType is created, then its contents are copied into this->key. The problem is that we have no way of accessing the newly created variable – we haven’t chosen to store a pointer to it anywhere (all we do is copy its contents). This means we can’t release the memory; the following line is also affected by the same problem.

Thankfully MSDN had a decent guide on Detecting and Isolating Memory Leaks which helped me to find the source of the errors, and enable me to embark on a two hour fixing session...

Enjoying a feeling of relief,

Andrew

Wtf? Failure

I may have overstated how well I was doing at university with that last post. I have managed to track down my Computing Profession module marks (and then a licensed copy of Microsoft Excel to open them). I managed an abysmal 28%, which would have been boosted to 40% or more had I not managed to get zero marks in my presentation. I’m not quite sure how I managed to get zero, particularly since I had another 2 large sections of the presentation (other than the one I scuppered) which I believe I did very well in. I’m going to have to find out how to query marks awarded, speak to the lecturer, and maybe even appeal... or just retake the module :`(

A not so happy teddy bear,

Andrew

Update: In a bizarre twist I have logged into the University's official marks repository, and found that I have passed with 45.2%... Additionally I have a provisional grade for Computer Systems: 70.6% which is still pretty darn good, that brings my overall percentage for my first trimester to 70.6% - damn i'm good :-).

1st Trimester Results

So far this year I feel that I have done pretty well, except for one fairly major cock-up in a Computer Profession Presentation which I hope was well recovered by the other two parts of the presentation. As of yet, I have only managed to get one portion of my results which was for my Introduction to Programming module – and i’m chuffed. I also found the coursework markings quite entertaining to read... Here are my lecturers overall comments:

There is modular and there is MODULAR. As an exercise in writing reusable code, demonstrating the professional qualities of your work and (let's be honest) implementing a piece of code to within an inch of its life, this is up there with the best. One thing you do learn as a professional is over-engineering is sometimes a waste of time - all that happens is you finish the job and the customer says "no, that's not what I wanted!". I'm not going to say that. This is a brilliant piece of work - you could easily have submitted a small subset of it and got full marks. The bit that worries me is that each of you gave the other (and yourself) 5/10 - jeeze - what would you have to do to deserve an A? I have built professional-level database implementations that were sold to multiple companies and used over 10 years with fewer source files than this.

Just to clarify, all results are still to be validated by a formal exam panel, so they aren’t set in stone just yet. If you want to read more of that check out Introduction to Programming ’08 Coursework Results. But yes, what was the result? A whopping:

96%

Not bad for a first attempt eh? Now I just need to find out what my other marks were – I like this a lot. And to think, my highest mark in the last two years was something like 71%: university seems to be the right idea :-).

Just plain happy,

Andrew

Student Offers

Since i’ve been at university i’ve had a few people ask me about student offers and where I can find specific pieces of Microsoft software for free (or a minimal price) while keeping it totally legal. For your convenience i’ve decided to compile a list:

For a fee...

For free...

And finally, if you may want to quiz your university about the “Microsoft Academic Alliance” since you can access a vast library of software ranging from MS-DOS to Windows Server 2008 Cluster Systems Edition, Visual Studio 2005 to Visual Studio 2008 Team Systems Edition for absolutely nothing (depending on your universities terms and conditions).

Enjoying the freebie life,

Andrew