Re: [Week 1] Sample Game Programming Interview Question

stayscrisp, so there is only 1 right answer? Also would this question be for Experienced ? Senior ? Junior? Or you would not care, and just ask the candidate?

There is no exactly right answer, it's just to get you thinking and see what you come up with. A good answer would at least show that this is something you have thought about and have some knowledge of

Re: [Week 1] Sample Game Programming Interview Question

Posted 11 February 2011 - 02:38 PM

Apart from the already mentioned answers I would try to remove the virtual function as it would create a vtable pointer. 's answer would also be something that would make a good difference to the size and if the health value was something like 0-100 then a char would be better than an int. That's what I came up with

Re: [Week 1] Sample Game Programming Interview Question

Posted 18 February 2011 - 10:52 AM

stayscrisp, on 03 February 2011 - 05:46 PM, said:

Question 1

Look at this class declaration can you calculate how much memory an instance of this class would take up?
You may have to make some assumptions, please list them too. What improvements could you make so that this class could take up less memory?

I had to do some research for this, so I hope the information I looked at was correct. I also made a couple of assumptions. Thanks for this questions, should help keep my skills sharp as I have been in a non-programming position for about 1.5 years out of college, but thankfully I am moving into one in two weeks. Thanks again for taking the time to do this!

Re: [Week 1] Sample Game Programming Interview Question

Posted 04 January 2012 - 03:13 PM

The destructor isn't virtual, but the GetMesh() is..
Which means it's meant to be derived from... I see a possible memory leak if the destructor deallocates memory.
It already has a vtable because GetMesh has the virtual keyword.

You can replace the Quaternion with 3 Euler angles. This can be converted into a Quaternion if necessary at runtime.
Of course it may be easier to keep it as a Quaternion (for interpolation and gimble lock avoidance, etc.)
Someone already mentioned the bit flags. Good idea.

Correct me if I'm wrong, I don't know much about padding, but I believe the compiler will auto-pad the class if the variables aren't aligned to some bytes...
I don't know though..

Design-wise: You could start off by stating that this code is complete crap. I'm sure this would get them interested.

The cohesion is very low. Notice that the class groups "health" and "orientation" together in the same class...
They don't have anything to do with one another.
You could, oh I don't know..... factor out position, velocity, and orientation into say, some sort of component... Like a physics component...

Or, for runtime optimization: It looks like you could use Data Oriented Design...
This class is a perfect example of cache poisoning.. Or cache pollution... If we have an array of game objects, for example, we have, not only the good stuff in the cache lines, we have the useless crap too... We only want good stuff... When the integrator loops through each game object, it has useless crap it doesn't need in there, such as health... So where does it have to fetch the next position/velocity/etc. from? Main memory because the cache is all full of useless crap.

Create an array of velocities, an array of positions, an array of orientations... So when the integrator loops through these arrays and updates them all,
the next position (or whatever) will will be in the cache already.. It's locality of reference will be good.

Data oriented design will, not only be faster, it'll decrease the footprint of all the game objects in the game because less padding will be used per game object... right?
I dunno, I'm not 100% sure about the padding.

Re: [Week 1] Sample Game Programming Interview Question

Posted 19 June 2015 - 11:16 AM

stayscrisp, on 03 February 2011 - 05:46 PM, said:

Sample Interview Question 1

I am going to be posting a weekly sample interview question for you guys to try out /> if you don't know the answer then you should look it up, this stuff is essential and will serve you well in the future.

Please put your answer between spoiler tags (like code tags but with the word spoiler instead) so people can read the thread without getting the answers straight away. OK then...

Question 1

Look at this class declaration can you calculate how much memory an instance of this class would take up?
You may have to make some assumptions, please list them too. What improvements could you make so that this class could take up less memory?

The answer is with variable alignment . The order you put the variable can reduce the number of padding . Obviously a class size is with its data , in the best world the size is exactly the sum of all data size , but the compiler is not perfect and add pad to fit data into 16bits block generaly . If you dont know the order it is fine , but you can tell variable allignment and you are good to go .