M
MrThingy
How can I have a function within a class that I know is going to be
called almost thousands of times during a loop cycle and have it run as
fast as possible, without using bug-prone #define macros?
I've read some information that says that ordinary Class member
functions running on private data tend to be optimised by the compiler
anyway?
-------------
Long boring bit: I'm currently converting an old program which has a
global array of the form:-
int *heightMap; // standard heightfield for landscape
which is allocated size:-
heightMap = new int[width * height]; // where "width" and "height" are
stated using #defines.
I used to access this array using a cheap and nasty #define function.
#define indexMap(x, y) ((x)&(width-1) + ((y)&(height-1)) * width) // yuck!
I'm now rewriting the code using sensible and easy to read classes, but
I'd like to be able to call something like:
current_height = Landscape.indexMap(x, y);
int Landscape::indexMap(int x, int y) {
return ((x)&(width-1) + ((y)&(height-1)) * width)
}
lots of times during the main program loop.
called almost thousands of times during a loop cycle and have it run as
fast as possible, without using bug-prone #define macros?
I've read some information that says that ordinary Class member
functions running on private data tend to be optimised by the compiler
anyway?
-------------
Long boring bit: I'm currently converting an old program which has a
global array of the form:-
int *heightMap; // standard heightfield for landscape
which is allocated size:-
heightMap = new int[width * height]; // where "width" and "height" are
stated using #defines.
I used to access this array using a cheap and nasty #define function.
#define indexMap(x, y) ((x)&(width-1) + ((y)&(height-1)) * width) // yuck!
I'm now rewriting the code using sensible and easy to read classes, but
I'd like to be able to call something like:
current_height = Landscape.indexMap(x, y);
int Landscape::indexMap(int x, int y) {
return ((x)&(width-1) + ((y)&(height-1)) * width)
}
lots of times during the main program loop.