[Browse] [Tag cloud]

Log on:
Powered by Elgg

Rob Ashton :: Blog

March 20, 2007

With regards to Stephen's earlier post asking about some pointers on pointers in a revision lecture, I thought it would be an interesting exercise to explain how things work by doing some unusual things in C.

I'm going to try and help by providing a couple of facts about C/C++ in line with the revision topics Stephen suggested in the hope that people will read them, understand them, and go "hey, that's quite cool" (Even if you don't admit it).

An array is just a pointer to the first item in that array. The type that the array is defined as tells the compiler what the 'stride' is between items.

Let's just prove this a second with some scary code!

 Read that, and work out what the output is going to be based on the above information. I'll give you a second of text here and warn you I'm about to write the answer.

Ok, I made it a bit obvious, the above code will output 'A' to the console. If you're confused, then read on while I explain, then look at the example again until you understand.

Remember what I said above, that an array is just a pointer to the first item in that array.

char cake[10]; is just char* pCake = new char[10]; with the added bonus of having the data placed on the stack where it will be cleaned up automatically when it goes out of scope!

So:

Achieves effectively the same as:

(Of course, attempting to delete the stack based 'cake' will result in a memory violation, and forgetting to delete the heap based 'pCake' will result in a memory leak).

Now, because these are effectively the same, with the exception of re-assignment or deletion, whatever you can do to one of them, you can do to the other!

Consider the two functions outlined below:

Again, these are exactly the same. Personally I would never use Function Declaration Two, because I like honesty - and Function Declaration One is saying "Look, I want a pointer" - and because arrays ARE just pointers, you can always use that pointer as if you would an ordinary array!!!

So, assume we have a method body for Function Declaration One, and a program which uses it:

Note how the 'Array' and the 'Pointer' are interchangeable.

I've rambled on now, but with the above knowledge in tow, the first code sample shown becomes very obvious.

We've defined an array of characters, which as we know is just a pointer.

char cake[10];

We then declare a pointer, and assign it the value of cake + 5

char* pCake = cake + 5;

Think about what we've actually done there. Cake is just a pointer, and we've added 5 strides (a char is only one byte in size, so that's 5 bytes if you're really that interested!) to that pointer. A functionally equivelant bit of code would look like:

char* pCake = &cake[5];

That of course, is a bit of a long way around. Using those square brackets is just a shortcut to 'dereference' the pointer.

cake[5] is exactly the same as doing *(cake + 5)

So, pCake is just a pointer to the middle of the original array! You could quite easily write:

int valueOne = *(pCake-5);

Although you'd be mad to do so.

The rest is history of course. Because pCake[0] is dereferencing a pointer to the middle of cake ( or cake[5] to you and me ), we get the value from that location.

Open up a compiler, and play with the above code until you understand what I'm going on about. If you can get your head around this post, and these concepts, then you'll find that pointers aren't as scary as they seem. ;)

I'll make a post about dereferencing pointers to complex types (classes) later today when I have time.

Keywords: C++, Fun, Pointers

Posted by Rob Ashton | 2 comment(s) | Share

February 25, 2007

It's Sunday and I'm at work.

This in itself is not unusual, I quite often go into the office at the weekend to work on my own projects. It's a quiet location with a nice stereo system and coffee machine which make it 'not so quiet'.

This Sunday however, is different. Tomorrow the product I've been helping get into shape since leaving University last June finally goes out. DriveWorks 6 SP0.0 is about to be released to the masses and boy that is exciting.

We actually finished the product on Friday, but in order for it to go out tomorrow the installers need finalising, start menu shortcuts, executable names and paths, help needs linking in and final logos for the Installshield project need throwing in. (Ok, I admit I have one or two tasks in the actual product that need ploughing through, but I've known about them for a week now and just haven't gotten around to doing anything about them!).

I'm happy to give up my Sunday to do this - as my own projects have hit that brick wall where I can't seem to gather any motivation to push into them. Having spent the entirety of yesterday walking in circles and getting nothing done, sinking into a frustrated depression over this seeming incredibly likely - it's nice to have some goals and targets given to me to work with.

Therapy by work - it's the future.

Keywords: Code, DriveWorks, Life

Posted by Rob Ashton | 0 comment(s) | Share

February 09, 2007

I've formatted and installed Windows XP after several months of using Vista RTM.

Vista is stunningly beautiful. It works like a charm and all those lovely features it has to make life easier are brilliant, such as the easy networking and search features.

But, third party support with regards to software and drivers is abysmal, and even once the driver manufacturors released their RTM drivers performance and stability were quite frankly, still shocking.

Hell, Visual Studio 2005 - despite having a recent service pack applied still has many, many issues that I haven't been able to get around - particularly with the ASP.NET development server.

Things came to an annoying end a couple of days ago when I tried installing a TV Tuner I'd bought off the intarweb. Vista decided that instead of installing the drivers for that, it would 'forget' that my DVD drive existed. Since installing the official sound drivers for my laptop I've also found it impossible to use my microphone - seriously limiting my ability to talk to people on Skype.

I've been putting up with driver issues since installing it, but this is my second install of Vista and its back to crawling along and not being that enjoyable to use. I've also had my credential cache corrupt itself making me unable to log into my laptop until I walked to work so I could be on the same network as the domain controller.

I hope that it gets sorted out, and that the following few months will improve matters - but Microsoft's hope that gamers will somehow be buying Vista because it brings greater performance is a joke. Maybe in a few years once new games are all using DX10 and new hardware means that the performance degredation from running DX9 games under Vista is unnnoticeable, but for now - Vista is for those people who don't mind putting up with what should really still be classified as beta software. 

Btw Karsten, I haven't installed IE7 yet and I've just noticed that the log-in boxes under IE6 have teleported all the way down the right hand side of of the page so I have to scroll right the way down to log in :)

Keywords: Vista

Posted by Rob Ashton | 8 comment(s) | Share

February 08, 2007

I just spent the last hour on Second Life with Karsten, Shirley and a host of other academics from around the globe.

It was an interesting experience, assessing Second Life as a tool for assisting with e-learning - or at least I think that was the aim of the experiment.

The goal was to team people up and for each team to go hide a cube of a certain colour. I was teamed up with Beth Kanter and a guy called Juan/John.

I don't think any of us were experienced with Second Life and I was surprised at how fast everybody picked it up. Organising the teams to go and do things was difficult - but no more difficult than trying to organise a collaborative exercise online in any other fashion.

I dressed for the occasion in a somewhat different manner than everybody else, who seemed content looking like themselves/ordinary. I should be easy to spot in the photos, being that I'm big, multi-coloured and have eyes which are completely detached from the rest of me.

 

 

Waiting for everybody to arrive

Ooh, this looks like a good hiding spot

Probably a bit too obvious...

Ah, perhaps here is better

Aha, found Orange's box!

Keywords: E-learning, Second Life

Posted by Rob Ashton | 1 comment(s) | Share

February 06, 2007

So I've been invited to a meeting in Second Life on Thursday, and being an open minded person I've just set me up an account and logged in.

I am impressed with the user friendliness of it all. Within 5 minutes I was flying around, had typed in the coordinates for the Community of Practise area and went for a skydiving session.

I don't know what the dos and donts are when it comes to content creation, but I made myself an upside down pyramid in the zone, sat down on it and will wait there until the meeting on Thursday.

Keywords: Community of Practise, Second Life

Posted by Rob Ashton | 0 comment(s) | Share

January 25, 2007

One of my internet friends has just finished (partially) a project written using SDL and C++. I thought this relevant considering I'll shortly be giving my SDL lecture at the university.

http://www.gametrailers.com/gamepage.php?id=4163

Brilliant stuff :)

Keywords: Bomberman Evolved

Posted by Rob Ashton | 0 comment(s) | Share

January 24, 2007

Having spent the past few hours in the bath reading "Harry Potter: The Half Blood Prince" from cover to cover through lack of anything better to do, I believe the time is appropriate to make a couple of predictions.

I tried defending Snape when everybody else was reading the book, and was beaten down by everybody saying that if he killed Dumbledore then he must be evil. So let's consider the facts.

1) He made that unbreakable vow thingy, it's not like he had a choice in the matter.

2) Dumbledore, a really intelligent chap had reason to trust the guy. He wasn't wrong on anything else now was he?

3) JK Rowling has said that two people are killed off in the next book.

4) Snape finds every excuse in the book possible as to why killing Harry is a bad idea. The only reason he's mean is because of the treatment he suffered from Harry's daddy.

So, not being a massive Harry Potter fan, I've forgotten what the other books are about, but I've read many more sophisticated 'fantasy' novels before and typically they tend to be quite predictable - like your favourite Sci-fi programs.

My predictions? The two people who get killed wll be Snape and Voldermort.  Snape will die defending Harry from the clutches of evil and Harry in his one redeeming moment(to be honest, the book annoyed me with his constant bickering) will go all out on Voldermort's ass and some righteous fury shall be let down on him.

 

And that's that done. I hope in a year's time when somebody has bought the book so I can steal it, I can look back at this post and go "Told you so".

Keywords: Harry Potter

Posted by Rob Ashton | 4 comment(s) | Share

January 20, 2007

Not going to post this on my personal blog because it's not a dead certain.

I've just been offered a job in London for 50% more than I'm currently being paid at DriveWorks. I'm probably going to turn it down.

It just goes to show that there are more important aspects to a job than the amount of money you're getting paid. I wish the train drivers would acknowledge that and stop striking ;)

Keywords: Money, Train Strikes

Posted by Rob Ashton | 4 comment(s) | Share

January 18, 2007

Holy crap!

The wind just blew the roof off the building next door, we were watching it shake about and then it lifted off and slammed into the wall and window where we were watching from. It then slammed into the building next door where the builders are working and it narrowly avoiding smashing through the window where they were stood.

Man that's intense.

Our phone lines are now down, as the roof also brought them with it. The lights have stopped flicking now though, as it was the roof next door that was causing our power issues, so we're safe with power for now.

I've tapped into a nearby wireless network, they must be another step back in the line before it reaches our building. So I have some weak internet for checking the trains for my trip tonight. The viaduct across Thelwall has been completely shut down so I'm probably in for a miserable journey as commuters try and find alternate ways home. (If the trains are still running!)

The power will hopefully remain on until then.

I feel sorry for whoever has to stay here tonight(probably Ian). Because we have no phone lines, our alarm system is locked down until an engineer comes down(or something like that). No alarms means no security, means insurance badness.

Keywords: Internet, Wind

Posted by Rob Ashton | 0 comment(s) | Share

Or possibly not.

I was called last night from a company based in London asking me if I wanted to come down for a job interview. As I'd already purchased tickets down to Reading this weekend and next weekend is cancelled because DriveWorks needs working on, on the surface it seems ideal that we conduct that interview this weekend.

Ah, not so. I'd unofficially decided that this weekend was going to be cancelled as well, because DriveWorks needs working on (anyone notice a trend here?) so I hadn't made any plans with the powers that be to take the day off work necessary to use these tickets.

So, I don't lie - its not in me, so the idea of taking a day off work under false pretences doesn't hold water. I rang my boss this morning who is currently in Reading and asked him for the day off and told him I was going for the interview.

I consider my current bosses to be friends and I really love the working environment, the amount of leeway given to me and their general attitude towards making DriveWorks a better place us to work. I'm not going to spring surprises on them like this, because it's just plain unfair.

I certainly hope they aren't offended by me at least scoping the place out - games development is somewhere I really want to be, and it's somewhere I've wanted to be for coming up on six years now, and while I'm maybe the happiest employee on the planet, I can't stop a fear of change stop me at least window shopping at whats out there.

It will take a lot to move me away from where I am currently, but it shouldn't stop me at least looking if opportunities come along?

So what do people think? What would do you tell your current employer if you had an impromptu interview like this and needed time off work?

Personally I think it's never worth lying, because when it catches up to you it always bites you in the ass.

Keywords: Career, Games Development, London, Lying

Posted by Rob Ashton | 4 comment(s) | Share

<< Back
/