Is it incorrect to use the precompiler like a complicated copy-and-paste tool? I've been working on a system where a few objects are processed according to exactly the same 'pattern' so to speak; BUT they are not related objects. Although it would be possible to bring some of them back to a common base class; I've read alot recently about virtual functions having a negative effect on a programs execution speed. The nature of this application is that it needs to be extremely fast. So shaving nanoseconds is important to a degree.
So, instead of writing out the same pattern of code many times, I made sure all of the objects had the same function names/usage, wrote the 'similar' processing functions once in an external file, and use #include and some #defines to make the functions even more re-usable under different circumstances. I feel like it's a good use of the precompiler; that it's making my program faster, that I'm still typesafe (compiler will spit errors if the precompiler generates insane code), and that my code is still manageable (at least, more manageable than if I was actually copy-pasting).
This is only neccessary in one part of my program, where lots of different data objects pass through chains of connected manipulator objects, each on different processing lines. All the processing lines do essentially the same thing with the object they recieve, and put it back on the same line; UNTIL they hit certain objects, which need to know the line that the object is coming in on, and the type of object (which is ok because different objects go on different processing lines). There's six processing lines in pairs, so three object types. In most cases, a single manipulator's six functions can be brought to a single pattern, and that function is the one that's being included externally. (that description is a replacement for actual code; it's too much data to paste/attach)
What do you guys think? Would you use the precompiler like that, or use some other (general) method? Are virtuals really that bad? I'm having plans to limit their usage elsewhere... but that depends on benchmark results =P