Factory Classes
In my engine I want to have maths code for different processors stored in plugin .DLL files that I load at runtime depending on which processor is used. The thing is, this introduces virtual function calls into my classes. This is ok for certain things, but not for things like my vertex class which is going to used thousands of times per frame.
I saw a post on here the other day where someone suggested using factories to solve this problem, but now I can''t find it. Can anyone help?
If the factory method doesn''t solve this problem can you post it anyway as i''m curious....
cheers
jx
Well, using a dll doesn''t make the function call virtual, it just uses function pointers. A virtual call requires an array index, and then a function pointer dereference.
I don''t think dll''s or a factory is a good solution to cpu optimized math ops. You''ll probably lose the performance gain in the overhead, 10x over...
I don''t think making optimized MatrixMult''s, K6, K7, P2, P3, P4, etc... and using a funtion pointer for each call is efficent... You''d need three seperate engines - like the same code compiled to three/four/whatever dlls depending on switches, so that the code is right in there. And GameStart is the dll call, instead of every MatrixMult.
Anyway, an IMathFactory
You could make a specific IVectorMath, & an IMatric, IQuaterion, etc... and have the MathFactory make each one for you.
You could put all this stuff in a dll, and then you could add support for new processors by updating the dll (screams COM). Again, I don''t recommend that route for performance reasons, but it could be interesting to see how bad it is.
Magmai Kai Holmlor
- The disgruntled & disillusioned
I don''t think dll''s or a factory is a good solution to cpu optimized math ops. You''ll probably lose the performance gain in the overhead, 10x over...
I don''t think making optimized MatrixMult''s, K6, K7, P2, P3, P4, etc... and using a funtion pointer for each call is efficent... You''d need three seperate engines - like the same code compiled to three/four/whatever dlls depending on switches, so that the code is right in there. And GameStart is the dll call, instead of every MatrixMult.
Anyway, an IMathFactory
|
You could make a specific IVectorMath, & an IMatric, IQuaterion, etc... and have the MathFactory make each one for you.
You could put all this stuff in a dll, and then you could add support for new processors by updating the dll (screams COM). Again, I don''t recommend that route for performance reasons, but it could be interesting to see how bad it is.
Magmai Kai Holmlor
- The disgruntled & disillusioned
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Additioanlly, function pointers break the branch prediction. The best way I can think of is to use nested if''s..
Chris Brodie
Sorry... in my original post I wasnt very clear.
Magmai Kai Holmlor:
The way you have show there is effectivley how I do it, just with the different classes stored in different .DLLs. All i do when I want to load a news maths class is have a function in the .DLL called getInterface() or something similar which returns a new CAMDMath object or whatever. This is the same as you have there really. What I was wondering is that because CAMDMath and CPIIIMath etc are derived from a base class which has the methods as virtual, doesn''t this make the calls virtual in all the derived classes and negate the optimisation?
The way I do it at the moment is as per this tutorial on GameDev:
http://www.gamedev.net/reference/programming/features/intdll/
My question is basically: Is this method too slow for things like vectors and matrices even with optimisation?
Jx
Magmai Kai Holmlor:
The way you have show there is effectivley how I do it, just with the different classes stored in different .DLLs. All i do when I want to load a news maths class is have a function in the .DLL called getInterface() or something similar which returns a new CAMDMath object or whatever. This is the same as you have there really. What I was wondering is that because CAMDMath and CPIIIMath etc are derived from a base class which has the methods as virtual, doesn''t this make the calls virtual in all the derived classes and negate the optimisation?
The way I do it at the moment is as per this tutorial on GameDev:
http://www.gamedev.net/reference/programming/features/intdll/
My question is basically: Is this method too slow for things like vectors and matrices even with optimisation?
Jx
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement