Reputation:
I'm working with a very disjointed API that has me bridging a lot of gaps between its own internal types.
In several places I am using std::copy to promote arrays of floats to arrays of doubles, or demote from arrays of doubles to arrays of floats to shuttle things between some of its more inconsistent objects.
Question is: Is that still considered the safest and closet-to-optimal way to do it, or are there recommended alternatives I should consider?
In case it helps if there are some platform specific ones, the following is the platform case: Deployment is internal and very limited, only gcc 4.8, only Linux, very local and controlled use. I can consider "dangerous" platform specific alternatives that might be undefined on other platforms if they are worth it in terms of performance.
Size of copies varies between a handful of triplets to, rarely, thousands of entries in one or two arrays. Length of source and targets are always the same, so simplest case for a copy possible, never ranged or conditional.
Upvotes: 2
Views: 231
Reputation: 249394
The way you're doing it is perfectly fine, and will have close to optimal performance. If you really want to squeeze every drop of performance, you might need to write some SSE code by hand (e.g. using CVTPD2PS
), but I wouldn't bother unless profiling shows these conversions to be a hot spot in your application.
Upvotes: 1