Hi, I am new to C++ and OOP, I entered a contest in which we must make a program that will play a board game against other players programs, and I want to speed up my program. File size does not matter, I just need raw speed.
The contest will be run on a linux x64 computer, I am developing my program with Visual Studio.
I read on the internet about ways to speed up my program, but I was wondering if anyone could give me some general C++ performance boosting tips.
Basically, my program is built with a main "game" class, inside which are many "board" classes, which each contain about a hundred "square" classes. I read the structs are faster than classes, but making the program with structs was too complex.
My program does lots of calculations with small integers (like between 0 and 10)
I might add recursion into the program.
I don't have time to start doing tricks with bits and stuff to make my program faster, but is there any general things I can do that will speed things up?
By the way, the contest will be held on a 4 core computer, and I do have quite a few calculations to do that aren't connected to each other. Will threading my program really speed it up? If yes, then can anyone recommend me a threading tutorial that will be easy to understand, and give me tips on threading.
Here is some general questions I was wondering:
I read that ints are the fastest types, are they really faster then shorts or even chars for just holding small numbers and doing simple addition?
How exactly am I supposed to pass class objects to other objects if it is for reading them only? Like this? void func(const MyClass& a)
How much slower is it to read a int inside a class than it is to just read a int?
A question not connected to speed: How do I make a class object inside a namespace, when inside the class itself, there are functions that use variables inside the namespace? Whichever I put first, the compiler complained that the other wasn't defined yet. Do I need to declare one first? I tried writing "class MyClass;" before the namespace, and after the namespace writing the whole class, but that didn't work. I don't want the classes themselves to be in the namespace. Please show me an example if you can.
And when are namespace variables initialized? At the start of the program?
Thanks for all the help, the contest will be over in about a week