We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I've ported some code from C to C++ and I'm shocked at how much more slowly it runs. I've written a lot of C++ in the past, so I know I haven't done anything absurdly inefficient, but execution times have gone up by 150% (2.5 times slower!). Has anyone else seen anything like this? Are there any particular aspects of the Keil C++ implementation that I should look out for?
There's too much code to post, but here's an overview.
The purpose of the function is to look for an address range (start address to end address) in a list of allocated address ranges. This involves doing a lot of address comparisons, where the addresses are 48 bits long. The C code uses a structure to hold the address which consists of an upper 16 bits and a lower 32 bits, and a function is called to compare structures.
The C++ implementation defines a class with the same member variables as the old C structure. Operator methods are the defined for the >= and <= operators, which perform the same comparison as the old C comparison functions. The operators use "pass by reference".
As the data and functions are fairly similar between C and C++, I wasn't expecting a huge difference in execution speed. I've had a quick look at the intermediate C produced by the C++ preprocessor, and it's virtually unreadable. I might have to give it more mental effort, but pointers in the right direction would be appreciated.
Can't you just keep it as a 'C' section in an otherwise C++ project?
Borland lets me do that...
Or build it separately as a Library?