Sunday, 27 April 2008

How to switch between .H and .CPP files in visual studio.

I've written a macro for this, since I don't know any existing commands in VS.

Sub SwitchBetweenHeaderAndSource()
Dim oldFile As String
Dim newFile As String
oldFile = DTE.ActiveDocument.FullName
If (oldFile.EndsWith(".cpp")) Then
newFile = oldFile.Replace(".cpp", ".h")
Else
If (oldFile.EndsWith(".h")) Then
newFile = oldFile.Replace(".h", ".cpp")
Else
newFile = oldFile
End If
End If
Dim pi As EnvDTE.ProjectItem
pi = DTE.Solution.FindProjectItem(newFile)
If (Not pi Is Nothing) Then
pi.Open().Activate()
End If
End Sub

You can write this macro in macro explorer, which you can find in Tools->Macros menu.
To assign a keyboard shortcut, you can go to Tools->Customize and click the Keyboard button. On that window you can find the macro and assign it a keyboard shortcut. I'm using Ctrl+"

Tuesday, 1 April 2008

This summer

I had applied to Realtime Worlds for a summer placement job. I got a quiz, and an interview today. I've got an email that says I'm accepted for a summer placement, I'm quite glad to hear that :)

I'll finish my coursework earlier and go to turkey for a three-week holiday with family&friends, and from the beginning of the June, I'll be working at RTW for three and a half months. Yee-haw cowboy!

References:
A saying that Raymond Chen has used in this article:
- Yee-haw cowboy: http://blogs.msdn.com/oldnewthing/.../45481.aspx
A great latin-jazz album from Ayhan Sicimoglu:
- Friends&Family: http://www.amazon.co.uk/Friends-Family-Sicimoglu....

Wednesday, 5 March 2008

c++ benchmark: list or vector?

In games programming, it's likely to have a collection of objects you want to draw to the screen. In some cases, the number of items in such a collection can be quite high.

I wondered if there's an efficient option between using std::list or std::vector, and I did a benchmark to see it myself.


Scenario 1: Insert n items, traverse n times.

when n=100, there isn't a huge difference but list is better. For vector it's between 15ms and 78ms, and for list it's between 15ms and 62ms.
When I calculate the average of rates, I can see that list is ~%11 faster.

when n=300, I can't see a clear winner. For vector it's between 200ms and 310ms, and for list it's between 203ms and 343ms.
According to the average of rates, vector is ~%3 faster.

Here's the source for this benchmark:http://pastebin.com/f41f684cb



Scenario 2: Insert n items, traverse n times and replace %20 of items on every iteration whilst traversing.


when n=100, mostly list wins. For vector it's between 170msms and 250ms, and for list it's between 172ms and 190ms.
List is ~%5 faster on average.

when n=200, list is always the winner. For vector it's between 1360ms and 1531ms, and for list it's between 1297ms and 1422ms.
List is ~%7 faster.

Here's the source for this benchmark:http://pastebin.com/f522f7e6b


Conclusion

If the number of items in your world are around 300 or more, and you don't perform so many insert&remove operations, pick vector. Otherwise, pick list.

I think the reason behind the truth that vector can't deal with continuous insert&remove operations is that it has to relocate remaining elements in the array when you delete one of them. For list, it's far more easy because it's implemented as a linked-list which means it's just about modifying two pointers to remove an element.

On the other hand, I think the reason why the list beats vector for 100 items is about the allocation strategy that vector uses. I don't know exactly how MS implemented this in standard library, but it's generally something like doubling the allocated memory everytime it's completely consumed. If it starts with a number like 5, to reach 100 it must be doubled 5 times, and everytime it looks for a bigger chunk of memory. The memory management has to find a continuous part in the memory for it. And after 100, to reach 300 it hast to be doubled just twice.

Saturday, 23 February 2008

Visual studio 2005 culture problem

Ok, I admit that it isn't a "problem". While working on our project "geekers", every time we update our project folder from subversion, we get this change to visual studio project file of the visual studio:


Ok, it's a desirable feature to have culture-specific data types in the xml streams. But do we really deserve this situation in this screenshot? I think we don't. :)
It remembers me a great article of Joel Spolsky, on "leaky abstractions."

Wednesday, 20 February 2008

Microsoft's another investment

As you can see on this page, microsoft is giving some of its products (visual studio, xna, windows server) to the students in UK for free. I've learned from Euan from our games project. I've already got those products thanks to MSDN membership of my university in Izmir, and many universities do.

An article I've read on 'Joel on software' claims that microsoft indeed would love to give its development products for free. Because the value of an operating system is dependent on the various software it has on it, and windows (with office) is the flagship product of microsoft. -- not visual studio --

I've never thought about it this way, and it really sounds smart.

Monday, 4 February 2008

Visual Studio SP1: Installation source for this product is not available

While trying to install Visual Studio 2005 SP1, I've encountered this error message: "Installation source for this product is not available".

After spending my whole day on this problem, I've found this blog entry:
http://dotnetslackers.com/...is_not_available.aspx

And this MSDN knowledge base entry & patch:
http://support.microsoft.com/default.aspx/kb/925336

And it managed to solve my problem. What a sunday!

Monday, 28 January 2008

Sun buys MySQL

It is not unreasonable, but it was unexpected; just like Serkan agreed. And in the digg post, the submitter's comment is: "Didn't see that one coming" :)

I can understand it, because the current commercial-opensource hybrid status of java is just like how MySQL is running for years. Probably, sun has foreseen more profit in this kind of work model.

Through a software guy's eye, I can tell that MySQL will strenghten its connections with Java, and it will implement/stabilize features which java used to supply from Oracle. Because of their strong relationship in the industry, this is something important for Oracle, as well.